Home » Eclipse Projects » EclipseLink » Native Query using function not finding primary key(When calling a function, EL unable to decode result correctly)
Native Query using function not finding primary key [message #807707] |
Sun, 26 February 2012 22:53 |
Hal Hildebrand Messages: 12 Registered: February 2012 |
Junior Member |
|
|
I create a simple function which selects all the rows in a table. I then create a Native query which calls this function, setting the resultClass to the entity that maps to the result of the function. When run, Eclipselink fails with the following error:
Exception Description: The primary key read from the row [ArrayRecord(
=> (2,bar,1))] during the execution of the query was detected to be null. Primary keys must not contain null.
Query: ReadAllQuery(name="relationship.getAll" referenceClass=Relationship sql="select r from test.get_relationships() as r")
Attached is a complete test case for this problem.
[Updated on: Mon, 27 February 2012 00:56] Report message to a moderator
|
|
| | |
Re: Native Query using function not finding primary key [message #808321 is a reply to message #808265] |
Mon, 27 February 2012 16:54 |
Hal Hildebrand Messages: 12 Registered: February 2012 |
Junior Member |
|
|
Here is the result of running the test with log level FINEST. As you can verify from the test case's persistence.xml, the property is set to true:
<property name="eclipselink.jdbc.uppercase-columns" value="true"/>
Running test.TestRelationship
[EL Finest]: 2012-02-27 08:52:19.576--ServerSession(55821173)--Thread(Thread[main,5,main])--Begin predeploying Persistence Unit test; session file:/Users/hhildebrand/git/eclipselink-function-query/target/classes/_test_url=jdbc:postgresql://localhost:5432/test_user=postgres; state Initial; factoryCount 0
[EL Finest]: 2012-02-27 08:52:19.59--ServerSession(55821173)--Thread(Thread[main,5,main])--property=eclipselink.orm.throw.exceptions; default value=true
[EL Finest]: 2012-02-27 08:52:19.59--ServerSession(55821173)--Thread(Thread[main,5,main])--property=eclipselink.multitenant.tenants-share-emf; default value=true
[EL Finest]: 2012-02-27 08:52:19.591--ServerSession(55821173)--Thread(Thread[main,5,main])--property=eclipselink.multitenant.tenants-share-cache; default value=false
[EL Finest]: 2012-02-27 08:52:19.609--ServerSession(55821173)--Thread(Thread[main,5,main])--property=eclipselink.metadata-source; default value=null
[EL Finer]: 2012-02-27 08:52:19.609--ServerSession(55821173)--Thread(Thread[main,5,main])--Searching for default mapping file in file:/Users/hhildebrand/git/eclipselink-function-query/target/classes/
[EL Finer]: 2012-02-27 08:52:19.611--ServerSession(55821173)--Thread(Thread[main,5,main])--Searching for default mapping file in file:/Users/hhildebrand/git/eclipselink-function-query/target/classes/
[EL Config]: 2012-02-27 08:52:19.746--ServerSession(55821173)--Thread(Thread[main,5,main])--The access type for the persistent class [class test.Relationship] is set to [FIELD].
[EL Config]: 2012-02-27 08:52:19.785--ServerSession(55821173)--Thread(Thread[main,5,main])--The target entity (reference) class for the one to one mapping element [field inverse] is being defaulted to: class test.Relationship.
[EL Config]: 2012-02-27 08:52:19.787--ServerSession(55821173)--Thread(Thread[main,5,main])--The alias name for the entity class [class test.Relationship] is being defaulted to: Relationship.
[EL Config]: 2012-02-27 08:52:19.816--ServerSession(55821173)--Thread(Thread[main,5,main])--The column name for element [id] is being defaulted to: ID.
[EL Config]: 2012-02-27 08:52:19.818--ServerSession(55821173)--Thread(Thread[main,5,main])--The column name for element [name] is being defaulted to: NAME.
[EL Config]: 2012-02-27 08:52:19.82--ServerSession(55821173)--Thread(Thread[main,5,main])--The sequence name for the sequence generator named [relationship_id_seq] defined on [class test.Relationship] from [class test.Relationship] is being defaulted to: relationship_id_seq.
[EL Config]: 2012-02-27 08:52:19.85--ServerSession(55821173)--Thread(Thread[main,5,main])--The primary key column name for the mapping element [field inverse] is being defaulted to: ID.
[EL Finest]: 2012-02-27 08:52:19.851--ServerSession(55821173)--Thread(Thread[main,5,main])--End predeploying Persistence Unit test; session file:/Users/hhildebrand/git/eclipselink-function-query/target/classes/_test_url=jdbc:postgresql://localhost:5432/test_user=postgres; state Predeployed; factoryCount 0
[EL Finer]: 2012-02-27 08:52:19.851--Thread(Thread[main,5,main])--JavaSECMPInitializer - transformer is null.
[EL Finest]: 2012-02-27 08:52:19.851--ServerSession(55821173)--Thread(Thread[main,5,main])--Begin predeploying Persistence Unit test; session file:/Users/hhildebrand/git/eclipselink-function-query/target/classes/_test_url=jdbc:postgresql://localhost:5432/test_user=postgres; state Predeployed; factoryCount 0
[EL Finest]: 2012-02-27 08:52:19.852--ServerSession(55821173)--Thread(Thread[main,5,main])--End predeploying Persistence Unit test; session file:/Users/hhildebrand/git/eclipselink-function-query/target/classes/_test_url=jdbc:postgresql://localhost:5432/test_user=postgres; state Predeployed; factoryCount 1
[EL Finest]: 2012-02-27 08:52:19.859--ServerSession(55821173)--Thread(Thread[main,5,main])--Begin deploying Persistence Unit test; session file:/Users/hhildebrand/git/eclipselink-function-query/target/classes/_test_url=jdbc:postgresql://localhost:5432/test_user=postgres; state Predeployed; factoryCount 1
[EL Finer]: 2012-02-27 08:52:19.873--ServerSession(55821173)--Thread(Thread[main,5,main])--Could not initialize Validation Factory. Encountered following exception: java.lang.NoClassDefFoundError: javax/validation/Validation
[EL Finest]: 2012-02-27 08:52:19.904--ServerSession(55821173)--Thread(Thread[main,5,main])--property=eclipselink.logging.level; value=FINEST; translated value=FINEST
[EL Finest]: 2012-02-27 08:52:19.904--ServerSession(55821173)--Thread(Thread[main,5,main])--property=eclipselink.logging.level; value=FINEST; translated value=FINEST
[EL Finest]: 2012-02-27 08:52:19.904--ServerSession(55821173)--Thread(Thread[main,5,main])--property=eclipselink.jdbc.bind-parameters; value=false
[EL Finest]: 2012-02-27 08:52:19.904--ServerSession(55821173)--Thread(Thread[main,5,main])--property=javax.persistence.jdbc.user; value=postgres
[EL Finest]: 2012-02-27 08:52:19.904--ServerSession(55821173)--Thread(Thread[main,5,main])--property=javax.persistence.jdbc.password; value=xxxxxx
[EL Finest]: 2012-02-27 08:52:20.168--ServerSession(55821173)--Thread(Thread[main,5,main])--property=eclipselink.target-database; value=POSTGRESQL; translated value=org.eclipse.persistence.platform.database.PostgreSQLPlatform
[EL Finest]: 2012-02-27 08:52:20.169--ServerSession(55821173)--Thread(Thread[main,5,main])--property=javax.persistence.jdbc.url; value=jdbc:postgresql://localhost:5432/test
[EL Finest]: 2012-02-27 08:52:20.17--ServerSession(55821173)--Thread(Thread[main,5,main])--property=eclipselink.jdbc.uppercase-columns; value=true
[EL Info]: 2012-02-27 08:52:20.171--ServerSession(55821173)--Thread(Thread[main,5,main])--EclipseLink, version: Eclipse Persistence Services - 2.3.2.v20111125-r10461
[EL Config]: 2012-02-27 08:52:20.181--ServerSession(55821173)--Connection(1550766882)--Thread(Thread[main,5,main])--connecting(DatabaseLogin(
platform=>PostgreSQLPlatform
user name=> "postgres"
datasource URL=> "jdbc:postgresql://localhost:5432/test"
))
[EL Config]: 2012-02-27 08:52:20.25--ServerSession(55821173)--Connection(1742392524)--Thread(Thread[main,5,main])--Connected: jdbc:postgresql://localhost:5432/test
User: postgres
Database: PostgreSQL Version: 9.1.2
Driver: PostgreSQL Native Driver Version: PostgreSQL 9.0 JDBC4 (build 801)
[EL Finest]: 2012-02-27 08:52:20.251--ServerSession(55821173)--Connection(1742392524)--Thread(Thread[main,5,main])--Connection acquired from connection pool [default].
[EL Finest]: 2012-02-27 08:52:20.251--ServerSession(55821173)--Connection(1742392524)--Thread(Thread[main,5,main])--Connection released to connection pool [default].
[EL Finest]: 2012-02-27 08:52:20.256--ServerSession(55821173)--Thread(Thread[main,5,main])--sequencing connected, state is Preallocation_NoTransaction_State
[EL Finest]: 2012-02-27 08:52:20.256--ServerSession(55821173)--Thread(Thread[main,5,main])--sequence relationship_id_seq: preallocation size 1
[EL Info]: 2012-02-27 08:52:20.291--ServerSession(55821173)--Thread(Thread[main,5,main])--file:/Users/hhildebrand/git/eclipselink-function-query/target/classes/_test_url=jdbc:postgresql://localhost:5432/test_user=postgres login successful
[EL Finer]: 2012-02-27 08:52:20.305--ServerSession(55821173)--Thread(Thread[main,5,main])--Canonical Metamodel class [test.Relationship_] not found during initialization.
[EL Finest]: 2012-02-27 08:52:20.305--ServerSession(55821173)--Thread(Thread[main,5,main])--End deploying Persistence Unit test; session file:/Users/hhildebrand/git/eclipselink-function-query/target/classes/_test_url=jdbc:postgresql://localhost:5432/test_user=postgres; state Deployed; factoryCount 1
[EL Finer]: 2012-02-27 08:52:20.319--ServerSession(55821173)--Thread(Thread[main,5,main])--client acquired: 375652924
[EL Finer]: 2012-02-27 08:52:20.334--ClientSession(375652924)--Thread(Thread[main,5,main])--acquire unit of work: 21006994
[EL Finest]: 2012-02-27 08:52:20.334--UnitOfWork(21006994)--Thread(Thread[main,5,main])--persist() operation called on: test.Relationship@344977e2.
[EL Finest]: 2012-02-27 08:52:20.335--ClientSession(375652924)--Thread(Thread[main,5,main])--Execute query ValueReadQuery(sql="select nextval('test.relationship_id_seq')")
[EL Finest]: 2012-02-27 08:52:20.336--ServerSession(55821173)--Connection(1742392524)--Thread(Thread[main,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2012-02-27 08:52:20.336--ServerSession(55821173)--Connection(1742392524)--Thread(Thread[main,5,main])--select nextval(test.relationship_id_seq)
[EL Finest]: 2012-02-27 08:52:20.356--ServerSession(55821173)--Connection(1742392524)--Thread(Thread[main,5,main])--Connection released to connection pool [default].
[EL Finest]: 2012-02-27 08:52:20.357--UnitOfWork(21006994)--Thread(Thread[main,5,main])--assign sequence to the object (1 -> test.Relationship@344977e2)
[EL Finest]: 2012-02-27 08:52:20.359--UnitOfWork(21006994)--Thread(Thread[main,5,main])--persist() operation called on: test.Relationship@21c783c5.
[EL Finest]: 2012-02-27 08:52:20.36--ClientSession(375652924)--Thread(Thread[main,5,main])--Execute query ValueReadQuery(sql="select nextval('test.relationship_id_seq')")
[EL Finest]: 2012-02-27 08:52:20.36--ServerSession(55821173)--Connection(1742392524)--Thread(Thread[main,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2012-02-27 08:52:20.36--ServerSession(55821173)--Connection(1742392524)--Thread(Thread[main,5,main])--select nextval(test.relationship_id_seq)
[EL Finest]: 2012-02-27 08:52:20.362--ServerSession(55821173)--Connection(1742392524)--Thread(Thread[main,5,main])--Connection released to connection pool [default].
[EL Finest]: 2012-02-27 08:52:20.362--UnitOfWork(21006994)--Thread(Thread[main,5,main])--assign sequence to the object (2 -> test.Relationship@21c783c5)
[EL Finer]: 2012-02-27 08:52:20.363--UnitOfWork(21006994)--Thread(Thread[main,5,main])--begin unit of work commit
[EL Finest]: 2012-02-27 08:52:20.368--UnitOfWork(21006994)--Thread(Thread[main,5,main])--Execute query InsertObjectQuery(test.Relationship@21c783c5)
[EL Finest]: 2012-02-27 08:52:20.368--UnitOfWork(21006994)--Thread(Thread[main,5,main])--Execute query WriteObjectQuery(test.Relationship@344977e2)
[EL Finest]: 2012-02-27 08:52:20.369--UnitOfWork(21006994)--Thread(Thread[main,5,main])--Execute query WriteObjectQuery(test.Relationship@21c783c5)
[EL Finest]: 2012-02-27 08:52:20.37--ServerSession(55821173)--Connection(1742392524)--Thread(Thread[main,5,main])--Connection acquired from connection pool [default].
[EL Finer]: 2012-02-27 08:52:20.37--ClientSession(375652924)--Connection(1742392524)--Thread(Thread[main,5,main])--begin transaction
[EL Fine]: 2012-02-27 08:52:20.371--ClientSession(375652924)--Connection(1742392524)--Thread(Thread[main,5,main])--INSERT INTO test.relationship (ID, NAME, inverse) VALUES (2, bar, NULL)
[EL Fine]: 2012-02-27 08:52:20.374--ClientSession(375652924)--Connection(1742392524)--Thread(Thread[main,5,main])--INSERT INTO test.relationship (ID, NAME, inverse) VALUES (1, foo, 2)
[EL Fine]: 2012-02-27 08:52:20.377--ClientSession(375652924)--Connection(1742392524)--Thread(Thread[main,5,main])--UPDATE test.relationship SET inverse = 1, NAME = bar WHERE (ID = 2)
[EL Finer]: 2012-02-27 08:52:20.389--ClientSession(375652924)--Connection(1742392524)--Thread(Thread[main,5,main])--commit transaction
[EL Finest]: 2012-02-27 08:52:20.392--ServerSession(55821173)--Connection(1742392524)--Thread(Thread[main,5,main])--Connection released to connection pool [default].
[EL Finer]: 2012-02-27 08:52:20.395--UnitOfWork(21006994)--Thread(Thread[main,5,main])--end unit of work commit
[EL Finer]: 2012-02-27 08:52:20.396--UnitOfWork(21006994)--Thread(Thread[main,5,main])--resume unit of work
[EL Finer]: 2012-02-27 08:52:20.398--UnitOfWork(21006994)--Thread(Thread[main,5,main])--initialize identitymaps
[EL Finer]: 2012-02-27 08:52:20.398--UnitOfWork(21006994)--Thread(Thread[main,5,main])--release unit of work
[EL Finer]: 2012-02-27 08:52:20.398--ClientSession(375652924)--Thread(Thread[main,5,main])--client released
[EL Finer]: 2012-02-27 08:52:20.398--ServerSession(55821173)--Thread(Thread[main,5,main])--client acquired: 142515426
[EL Finer]: 2012-02-27 08:52:20.399--ClientSession(142515426)--Thread(Thread[main,5,main])--acquire unit of work: 812498377
[EL Finer]: 2012-02-27 08:52:20.4--UnitOfWork(812498377)--Thread(Thread[main,5,main])--begin unit of work flush
[EL Finer]: 2012-02-27 08:52:20.4--UnitOfWork(812498377)--Thread(Thread[main,5,main])--end unit of work flush
[EL Finest]: 2012-02-27 08:52:20.401--UnitOfWork(812498377)--Thread(Thread[main,5,main])--Execute query ReadAllQuery(name="relationship.getAll" referenceClass=Relationship sql="select r from test.get_relationships() as r")
[EL Finest]: 2012-02-27 08:52:20.401--ServerSession(55821173)--Connection(1742392524)--Thread(Thread[main,5,main])--Connection acquired from connection pool [default].
[EL Finer]: 2012-02-27 08:52:20.401--ClientSession(142515426)--Connection(1742392524)--Thread(Thread[main,5,main])--begin transaction
[EL Fine]: 2012-02-27 08:52:20.402--ClientSession(142515426)--Connection(1742392524)--Thread(Thread[main,5,main])--select r from test.get_relationships() as r
[EL Warning]: 2012-02-27 08:52:20.421--UnitOfWork(812498377)--Thread(Thread[main,5,main])--Local Exception Stack:
Exception [EclipseLink-6044] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.QueryException
Exception Description: The primary key read from the row [ArrayRecord(
=> (1,foo,2))] during the execution of the query was detected to be null. Primary keys must not contain null.
Query: ReadAllQuery(name="relationship.getAll" referenceClass=Relationship sql="select r from test.get_relationships() as r")
at org.eclipse.persistence.exceptions.QueryException.nullPrimaryKeyInBuildingObject(QueryException.java:895)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:584)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:560)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.buildObject(ObjectLevelReadQuery.java:717)
at org.eclipse.persistence.queries.ReadAllQuery.registerResultInUnitOfWork(ReadAllQuery.java:769)
at org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:433)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1081)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:844)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1040)
at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:392)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1128)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2871)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1516)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1498)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1463)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.executeReadQuery(EJBQueryImpl.java:485)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getResultList(EJBQueryImpl.java:742)
at test.TestRelationship.testFunction(TestRelationship.java:53)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:35)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:146)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:97)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103)
at $Proxy0.invoke(Unknown Source)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:145)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:87)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.081 sec <<< FAILURE!
Results :
|
|
|
Re: Native Query using function not finding primary key [message #808386 is a reply to message #808321] |
Mon, 27 February 2012 18:30 |
|
Executing a native SQL query with a class, requires that the native query returns a result set that matches what the class requires.
The native query you are executing does not appear to return a matching result set.
From the error the row returned is,
ArrayRecord(
=> (1,foo,2))
Which seems to be a result with no column name at all, and the value is some kind of array structure.
What you need to be returned, to be able to map it is,
ArrayRecord(
ID => 1, NAME='foo', inverse=2)
Try something like,
select r.id as ID, r.name as NAME, r.inverse as inverse from test.get_relationships() as r
You could also try executing the SQL through an SQL tool, or with the class and a Map result to see exactly what it returns.
James : Wiki : Book : Blog : Twitter
|
|
| |
Goto Forum:
Current Time: Fri Apr 26 03:34:34 GMT 2024
Powered by FUDForum. Page generated in 0.03388 seconds
|