I cannot get composite keys to work with Batch insert statements. I have the following three objects (simplified to highlight problem):
public class Temporary {
@Id
public TemporaryPK id;
}
@Embeddable
public class TemporaryPK {
@Column(name = "USER_ID")
public String userId;
@Column(name = "LOCATION_ID")
public String locationId;
}
public class Location {
@Id
@Column(name = "LOCATION_ID")
public id;
}
I try to perform the following hql update:
insert into Temporary (id.userId, id.locationId) select :userId, location.id from Location location
And I get the following error:
java.lang.IllegalArgumentException: org.hibernate.QueryException: could not resolve property: of: Temporary [insert into Temporary (id.userId, id.locationId) select :userId, id.locationId from Location]
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:634)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:95)
at com.quantumretail.persistence.hibernate.HibernateSaver.save(HibernateSaver.java:20)
at com.quantumretail.persistence.hibernate.HibernatePersistenceManager.save(HibernatePersistenceManager.java:200)
at com.quantumretail.persistence.BasePersistenceTestCase.save(BasePersistenceTestCase.java:100)
at com.quantumretail.model.TemporaryLocationPersistenceTest.testBatchSave(TemporaryLocationPersistenceTest.java:34)
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:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
I have also tried:
insert into Temporary (userId, locationId) select :userId, location.id from Location location
And still no luck. Any idea if this can be done and if so, how I would do it?
Thanks...
|