-->
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.  [ 1 post ] 
Author Message
 Post subject: Entity references by non-primary keys
PostPosted: Mon May 30, 2005 9:01 am 
Newbie

Joined: Mon May 30, 2005 8:33 am
Posts: 1
I'm building a server that uses hibernate for it's data layer and I hava a client that creates entities through a remote interface.

Let's say that the client wants to create a new entity A which have many-to-one references to the already persisted entities B, C and D.

The entities B, C and D have primary keys generated by the server (hibernate) and they also have candidate keys. The clien't doesn't know the primary keys of the referenced objects but it knows the candidate keys. I would like the client to be able to be able to call the server like this:

Code:
b = new B();
b.setCandidateKey(XX);
c = new C();
b.setCandidateKey(YY);
d = new D();
b.setCandidateKey(ZZ);
a = new A();
a.setB(b);
a.setC(c);
a.setD(d);

server.create(a);


The point is that I don't want ther client to have to lookup all referenced objects to find their primary-keys. Now if I just try to save the value object 'a' on the server side (using session.merge()) I get an error because the referenced value objects doesn't contain primary keys and are treated as transient objects.

Do I have to make code that looks all referenced objects up and retrieves their primary keys or is there any way to make hibernate do this automatically (the candidate keys are unique, not-null and immutable)?


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

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.