-->
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: Persist only an id attribute of an object
PostPosted: Tue Jun 09, 2009 5:49 am 
Newbie

Joined: Tue Jun 09, 2009 5:27 am
Posts: 1
Hello,

first: I'm an absolute hibernate beginner. I'd bee searching the web for quite a while concerning this topic but haven't found an answer. I'd like to know if ithe following scenario is possible with hibernate:
I'd like to implement a service that persists an object X from my domain model. Therefore I annotate X to be persisted with hibernate. X has got a reference to a non-hibernate object Y. Within the table, only the id attribute of Y should be stored but no other attributes. The Y object should be somehow loaded when calling X.getY(). The external API has got a Method like YService.getY(yId).
Code:
@Entity
class X
@id
getId();
getString();
getNumber();
getY();

Code:
class Y // non annotated, external object
getYId();
getAttribute1();
getAttribute2();
...

Resulting table columns for X shoud look like these:

id string number yId


So I hope that anybody understoods my problem and can help me to find a solution or at least tell be if storing id attributes of external referenced objects are possible or not.

Regards
Felix


Top
 Profile  
 
 Post subject: Re: Persist only an id attribute of an object
PostPosted: Thu Jun 25, 2009 1:07 pm 
Newbie

Joined: Thu Jun 25, 2009 1:03 pm
Posts: 2
Hello,

did you try making the Y attribute Transient (with the @Transient annotation)?
If you only want to store Y's id you can create an attribute Yid in class X, and store that attribute in the DB instead of Y.

You can use @PrePersist and @PostLoad events to load Yid and your real Y respectively.

Hope that helps in some way.
Greetings


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.