-->
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.  [ 11 posts ] 
Author Message
 Post subject: Hibernate and existing object does not store PK in object
PostPosted: Wed Dec 22, 2004 12:05 pm 
Newbie

Joined: Fri Dec 17, 2004 5:23 pm
Posts: 6
Hibernate ver. 2.1.7

I have an object that is only read from the database. The object does not store the PK in the object because we never have to look up or modify anything once we retieve it. I can not modify the class to store the PK because of other systems' dependency on the class.

My suspicion is that I cannot use hibernate to map to this object with out the PK in the object.

Anyone have any ideas on what I can do?
Or, can you confirm that my suspicion is correct?

Thanks,

Curt Stanton


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 22, 2004 12:07 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You can let Hibernate manage the id only, just don't define a name on the id tag. You can not use object detachment in any way then however.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 22, 2004 3:48 pm 
Newbie

Joined: Fri Dec 17, 2004 5:23 pm
Posts: 6
Thank you. After you said that I re-read the descrption in chapter 5 and it was right there.

Here is the next problem I have run into with this. First off, I am trying to implement a cache of objects. In the cache I am using a Hashtable with the PK mapped to the object. Within a session, can I access the value of that PK to map that object in a hashtable?

Thanks again

Well, I decided to read a bit more before I posted this and I found my answer, just thought that I would share in case someone else has this question.

In Section 11.4, it describes how to select multiple objects/properties in HQL. It returns Object[].

Hibernate ROCKS!!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 22, 2004 3:51 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
and before you go implement your own caching stuff why don't you go read about hibernate's caching possibilities ? ,)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 22, 2004 4:06 pm 
Newbie

Joined: Fri Dec 17, 2004 5:23 pm
Posts: 6
I did, but we need to make 100% sure that the cache isn't dirty. So we always do at least on select to the DB to check timestamps for requested PKs then use the cache if the data is already there or create the object using hibernate and store it in our cache.

Unless of course you could enlighten me (point me in the right direction) on how to ge hibernate to do that?

I really do appeciate all your help.

-Curt Stanton


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 22, 2004 4:11 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
By using a read/write or transactional concurrency handling strategy. Really, what you are trying to do (or how you explain it) doesn't make much sense. Read up on the available documentation and Hibernate in Action.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 22, 2004 4:15 pm 
Newbie

Joined: Fri Dec 17, 2004 5:23 pm
Posts: 6
Sorry, I forgot to mention that I cannot guarantee exclusive access to the database. Other systems may access the database. That is what makes me think it would be difficult, if not impossible to use Hibernates caching features.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 22, 2004 4:18 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
It makes caching useless, in general.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 22, 2004 5:06 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
...but I would argue that it would be way better to use hibernates existing caching stuff and provide a way to mark the cache dirty when needed....instead of going invent yet-another caching mechanism....

just my 2 cents...

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 22, 2004 6:35 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
yes, of course this is the correct approach. SessionFactory provides operations for application-level invalidations.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 23, 2004 11:22 am 
Newbie

Joined: Fri Dec 17, 2004 5:23 pm
Posts: 6
I will check that out. Thank you all again for all the help.

The speed of answers on this forum is absolutely amazing.

-Curt


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