-->
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.  [ 8 posts ] 
Author Message
 Post subject: Access value of FK Ids without resolving relations?
PostPosted: Mon Jun 26, 2006 2:07 pm 
Newbie

Joined: Sun Jun 04, 2006 4:19 pm
Posts: 9
Location: Germany
When defining relations, you specify the join column(s) that carries the FK information. But let's say we use lazy fetching and are interested in the FK value without resolving the relation. I did not find how to express this with JPA annotations. Any ideas? Thanks in advance!

If it's not clear yet, I try to express it as an example using /*non working*/ pseudo annotations:
Variation 1:

@Column(name="customer_id")
int customerId;
@OneToOne
// non-existent annotation:
@JoinProperty(name="customerId")
Customer customer;


Variation 2:

@Column(name="customer_id")
int customerId;

@OneToOne
// Mapping exception: repeated column in mapping:
@JoinColumn(name="customer_id")
Customer customer;


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 27, 2006 6:09 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
You could probably use 2.
But be sure to set insertable=false, updateable=false .. since otherwise it will complain about duplicate columns.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 27, 2006 6:39 am 
Newbie

Joined: Sun Jun 04, 2006 4:19 pm
Posts: 9
Location: Germany
Because the relation must be updateable, I concluded this is not an option.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 27, 2006 6:54 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Ok, you leave this on one of the properties - but code in such way that when association changes, it also changes int value. The other way around is probably more difficult to write - but can be done with some EventListener impl.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 27, 2006 7:02 am 
Newbie

Joined: Sun Jun 04, 2006 4:19 pm
Posts: 9
Location: Germany
Thank you for your replies.
I am not sure if I understood you correctly. Does your description include resolving the relation? I need it without resilving the relation. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 09, 2006 7:29 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
map your property only once

in Hibernate (this is (might not be) not true for bytecode enhanced based persistence engine),

child.getParent().getId() (which is the FK value you're looking for) does not load the parent association

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 10, 2006 8:27 am 
Newbie

Joined: Sun Jun 04, 2006 4:19 pm
Posts: 9
Location: Germany
emmanuel, thank you for your reply. Did you mean Hibernate Core when you wrote of Hibernate? A solution working with JPA would be prefered though.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 16, 2006 7:10 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This will work on Hibernate Core and Hibernate EntityManager.
I cannot guaranty for others JPA implementations since most JDO based engine use buildtime enhancement rather than proxy for lazy loading because of the way the JDO spec has been designed.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.