Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] [Newbie] Problems with createNativeQuery

Hello,

What database are you using? This error is common when the case used for the returned column name doesn't match the case of the column name defined in the JPA annotations. In this case, since the @Id column name wasn't specified, it will default to "ID". So it could be that the default string "ID" isn't matching what is returned, for example if the database returns "id". Try specifying the Id column name to match what is returned by your database/driver and see if that helps.

Best Regards,
Chris



RogerV wrote:

Vackar wrote:
Sorry, forgot to say -  could you also post your stacktrace as well.


This appears on the console for getPlatformByNativeQueryById()

[EL Warning]: 2009-09-09 15:01:25.171--UnitOfWork(27109735)--Exception
[EclipseLink-6044] (Eclipse Persistence Services - 1.1.2.v20090612-r4475):
org.eclipse.persistence.exceptions.QueryException
Exception Description: The primary key read from the row [DatabaseRecord(
	 => 8
	Platform.PlatformName =>record8)] during the execution of the query was
detected to be null.  Primary keys must not contain null.
Query: ReadAllQuery(referenceClass=Platform sql="Select * from Platform
where id=8")

and the stacktrace raised by JUnit is as follows;

Local Exception Stack: Exception [EclipseLink-6044] (Eclipse Persistence Services -
1.1.2.v20090612-r4475): org.eclipse.persistence.exceptions.QueryException
Exception Description: The primary key read from the row [DatabaseRecord(
	 => 8
	Platform.PlatformName => record8)] during the execution of the query was
detected to be null.  Primary keys must not contain null.
Query: ReadAllQuery(referenceClass=Platform sql="Select * from Platform
where id=8")
	at
org.eclipse.persistence.exceptions.QueryException.nullPrimaryKeyInBuildingObject(QueryException.java:844)
	at
org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:464)
	at
org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:437)
	at
org.eclipse.persistence.queries.ObjectLevelReadQuery.buildObject(ObjectLevelReadQuery.java:569)
	at
org.eclipse.persistence.queries.ReadAllQuery.registerResultInUnitOfWork(ReadAllQuery.java:904)
	at
org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:490)
	at
org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:928)
	at
org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:664)
	at
org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:889)
	at
org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:458)
	at
org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:952)
	at
org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2756)
	at
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1181)
	at
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1165)
	at
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1139)
	at
org.eclipse.persistence.internal.jpa.EJBQueryImpl.executeReadQuery(EJBQueryImpl.java:389)
	at
org.eclipse.persistence.internal.jpa.EJBQueryImpl.getSingleResult(EJBQueryImpl.java:594)
	at
com.blackbox.entities.PlatformTest.getPlatformByNativeQueryById(PlatformTest.java:50)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
	at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
	at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
	at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
	at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
	at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
	at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
	at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
	at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)




Back to the top