Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » SQLResultSetMapping - aliases in NativeQuery not working
SQLResultSetMapping - aliases in NativeQuery not working [message #487404] Wed, 23 September 2009 06:50 Go to next message
Thomas Haskes is currently offline Thomas HaskesFriend
Messages: 147
Registered: July 2009
Senior Member
Hi,

I'm using the SQLResultSetMapping to map an entity to a nativeQuery and
found out that whenever I use aliases in the corresponding nativeQuery I
get this:

------------------------------------------------------------
Exception Description: The primary key read from the row [DatabaseRecord(
TESTRESULTMAPPING.PROP1 => null
TESTRESULTMAPPING.PROP2 => null
TESTRESULTMAPPING.PROP3 => null
TESTRESULTMAPPING.PROP4=> null)] during the execution of the query was
detected to be null. Primary keys must not contain null.
Query: ResultSetMappingQuery(referenceClass=TestResultMapping
sql="select v.col1 AS c_prop1, v.col2 as c_prop2, v.col3 as c_prop3,
v.col4 as c_prop4 from Table v")

------------------------------------------------------------ -------


As you can see it seems that the EL is not able to identify the aliases
used in the query above.
When I modify the query and the mapping not using aliases, it works.

The entity with the mapping using aliases is this:

------------------------------------------------------------ ----------

@Entity
@SqlResultSetMapping(name="TableResults",
entities = {
@EntityResult(entityClass=persistence.TestResultMapping.clas s,
fields= {
@FieldResult(name="prop1", column="c_prop1"),
@FieldResult(name="prop2", column="c_prop2"),
@FieldResult(name="prop3", column="c_prop3"),
@FieldResult(name="prop4", column="c_prop4")
})
})
public class TestResultMapping {
@Id
private String prop1;
private long prop2;
private String prop3;
private long prop4;


public String getProp1() {
return kontext;
}
public void setProp1(String prop1) {
this.prop1 = prop1;
}
... // more getters and setters
}

Query: sql="select v.col1 AS c_prop1, v.col2 as c_prop2, v.col3 as
c_prop3, v.col4 as c_prop4 from Table v")

------------------------------------------------------------ --------

The modified mapping not using aliases (that works) is this:

------------------------------------------------------------ --------

@EntityResult(entityClass=persistence.TestResultMapping.clas s,
fields= {
@FieldResult(name="prop1", column="col1"),
@FieldResult(name="prop2", column="col2"),
@FieldResult(name="prop3", column="col3"),
@FieldResult(name="prop4", column="col4")
})
})
public class TestResultMapping {

.... // like above
}

Query: sql="select v.col1 , v.col2, v.col3, v.col4 from Table v")

------------------------------------------------------------ -------

Is this a bug, or am I missing something?

Thanks in advance

Tom
Re: SQLResultSetMapping - aliases in NativeQuery not working [message #487816 is a reply to message #487404] Thu, 24 September 2009 13:54 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Odd, what database and JDBC driver, and what version f EclipseLink are you using?

Also try execute the raw SQL and see what columns are returned,

i.e.
((JpaEntityManager)em.getDelegate()).executeSQL("<sql>");

EclipseLink should be using the alias, not the column name.


James : Wiki : Book : Blog : Twitter
Re: SQLResultSetMapping - aliases in NativeQuery not working [message #490264 is a reply to message #487816] Thu, 08 October 2009 06:59 Go to previous messageGo to next message
Thomas Haskes is currently offline Thomas HaskesFriend
Messages: 147
Registered: July 2009
Senior Member
Sorry, i recently had no tome to look at this again.

I'm using EL 1.1.2, Oracle Database 10g Enterprise Edition Release
10.2.0.2.0, and the ojdbc Driver Version 10.1.0.4.2.


> Also try execute the raw SQL and see what columns are returned,
>
> i.e.
> ((JpaEntityManager)em.getDelegate()).executeSQL("<sql>");
>

I wasn't able to execute the code you suggested, as the JpaEntityManager
doesn't have the method executeSQL();

Tom
Re: SQLResultSetMapping - aliases in NativeQuery not working [message #490376 is a reply to message #487404] Thu, 08 October 2009 13:44 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

((JpaEntityManager)em.getDelegate()).getActiveSession().exec uteSQL( "<sql>");

James : Wiki : Book : Blog : Twitter
Previous Topic:v1.1+ attempts to INSERT a copy of unchanged data
Next Topic:UnitOfWork events
Goto Forum:
  


Current Time: Tue Apr 16 11:35:34 GMT 2024

Powered by FUDForum. Page generated in 0.35054 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top