-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Composite key with Insert Into statement.
PostPosted: Thu Jun 14, 2007 5:03 pm 
Newbie

Joined: Thu Jun 14, 2007 4:56 pm
Posts: 1
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...


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 29, 2007 8:22 am 
Newbie

Joined: Sat Sep 29, 2007 8:18 am
Posts: 2
I have exactly the same problem and no idea what direction to go.

I've tried to give up composite key but it's still happens even if I use it in a many-to-one.
Example

<class name="A">
<id name="id">
<generator class="native" />
</id>
<many-to-one name="b" class="B"></many-to-one>
</class>

If I try to execute the following HQL:
INSERT INTO A (id, b.id) select id, 1 from B;

I get the same error as above (it doesn't like the 'b.id').

Anybody? Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.