Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 368624 - createNativeQuery does not maps entities
Summary: createNativeQuery does not maps entities
Status: CLOSED WORKSFORME
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P2 major with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-15 11:51 EST by Viktor Bartuszek CLA
Modified: 2022-06-09 10:19 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Viktor Bartuszek CLA 2012-01-15 11:51:07 EST
Build Identifier: 2.3.2

When you use nativeQuery with type cast, then the resultset's first element is ok, but all the others are filled with nulls.

public List<UserStatusType> getEntities() {
		List<EntityName> res = new ArrayList<EntityName>();
		res = em.createNativeQuery("select * from tbl", EntityName.class)
			.getResultList();
		
		return res;
	}

If you annotating the entity with SqlResultSetMapping and sets all the fields that you need, then it's working fine.:

@SqlResultSetMapping(
	name="statusResult",
	entities=@EntityResult(
		entityClass=EntityName.class,
		fields={
			@FieldResult(name="id", column="ID"),
			@FieldResult(name="statusName", column="StatusName")
		}
	)
)

public List<UserStatusType> getEntities() {
		List<EntityName> res = new ArrayList<EntityName>();
		res = em.createNativeQuery("select * from tbl", "statusResult")
			.getResultList();
		
		return res;
	}

With version 2.2.1 it's also working fine with typecast and resultset mapping too.

Reproducible: Always

Steps to Reproduce:
1. create native query with a simple select
2. run it
3. create native query with a complete SqlResultSetMapping
4. run it
Comment 1 Tom Ware CLA 2012-02-09 10:29:10 EST
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines

Community: Please vote for this bug if it is important to you.  Votes are one of the main criteria we use to determine which bugs to fix next.
Comment 2 Chris Delahunt CLA 2012-02-17 10:18:13 EST
This does not have a test case, and our tests using Native queries to return entities are working, so I will have to mark this as works for me unless an example that reproduces is provided.  

Looking at the example resultset though, it suggests that "ID" is working while "StatusName" and the other fields that are not might have a mixed case.  As EclipseLink is case sensitive (or more that Java hashcodes are case sensitive) how the fields are defined must match how the fields are returned from the database in the resultset.  This is database dependent, but EclipseLink can be made to upper case everything to get around this using the "eclipselink.jpa.uppercase-column-names" persistence property.
Comment 3 Eclipse Webmaster CLA 2022-06-09 10:19:35 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink