-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hibernate questions
PostPosted: Sat Jan 10, 2004 8:45 pm 
Beginner
Beginner

Joined: Wed Oct 15, 2003 1:31 pm
Posts: 25
I have several questions which I would very much appreciate some help with. Thanks in advance.

1.I am planning to use Hibernate Sessions that span several transactions to complete a business process. If a Hibernate proxy is obtained within a transaction, can it be initialized outside of the transaction, but within the same Session (after disconnecting from the session)?

2.I have defined an inheritance hierarchy of Person -> Contact -> User, where Person is the base class and both Contact and User are concrete classes. I want to use the 2nd level cache for User objects, as they are referenced frequently and is ok without the latest version. From my quick read of net.sf.hibernate.mapping.Subclass, it appears that it is not possible to use the 2nd level cache for a subclass if the base class does not also use the 2nd level cache. So for example, I am led to believe that I would not be able to use the 2nd level cache for User if I did not also use it for Person and Contact.

Is this correct? If so, it would seem to break my intended use of 2nd-level caching, which is to cache Users, but not non-User Contacts in the 2nd level cache. If this is true, I'm thinking of making User a base class and creating a bidirectional reference between it and Contact, but that causes another problem for my design because some attributes of Person are needed for the most basic use of User, i.e. a list of UserS in which the first and last names are displayed (which are attributes of Person in my model). A hack to deal with that would be to store the fields needed to display a list of User objects in the User object/table, but I'd like to avoid so ugly a solution. Suggestions?

3.If I use a 2nd level cache (using ehCache) with usage=


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 10, 2004 10:23 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
1. Of course.

2. Correct, all classes in the hierarchy use the same cache.

3. Yes and yes.

4. It must be a property of the entity.

5. You have misunderstood. The objects returned from the query are, of course, always the current in-memory objects. However the actual rows returned by the query may be affected by the lack of synchronization (obviously regardless of whether it is find or iterate).

6. Just use an XML external entity.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 10, 2004 11:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Actually, my answer to 4 is not correct. You may use a custom PropertyAccessor to get/set the value from/to anyplace you like. See net.sf.hibernate.property package.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 11, 2004 2:05 pm 
Beginner
Beginner

Joined: Wed Oct 15, 2003 1:31 pm
Posts: 25
Thanks for the quick reply, Gavin. Two questions.

1. If I implement a custom PropertyAccessor, how do I get Hibernate to use it?
2. Do you think this is a good design approach -- would you use it?

Rick


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 11, 2004 2:13 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
For 1: use the access attribute of the property element: http://www.hibernate.org/hib_docs/reference/html/or-mapping.html#or-mapping-s1-7


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