-->
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.  [ 4 posts ] 
Author Message
 Post subject: How do a I specify class level lazy attribute w/annotations?
PostPosted: Mon Jun 06, 2005 8:45 pm 
Newbie

Joined: Mon Jun 06, 2005 3:49 pm
Posts: 3
I am just moving up to Hibernate 3.0.5 and Hibernate Annotations 3.0 beta 2 from Hibernate 2.1. I use "table per class hierarchy" inheritance for some of my classes, and need to load them by id with the base class:

Code:
session.load(BaseClass.class, databaseId);


However, this does not work with lazy/proxying enabled for the class. I searched this forum and the annotations docs, and cannot find anyway to specify lazy="false" using annotations at the class level. Is it possible to do, and if not, will it be available in a future release?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 12:11 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
What do you mean it does not work?? Of course it works.

Remember, proxy type != underlying instance type.

(Also, you can use get() instead.)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 9:03 am 
Newbie

Joined: Mon Jun 06, 2005 3:49 pm
Posts: 3
I'm sorry, my question was not clear.

My DAO exposes the method:

Code:
BaseClass getBaseClassById(Serializable databaseId)
{
    return (BaseClass)session.load(BaseClass.class, databaseId);
}


However, consumers of this API need to cast the returned value to specifc instances:

Code:
SpecificClass specificClass = (SpecificClass)dao.getBaseClassById(id);


When lazy loading is enabled for the class, and there is a table per class hierarchy, then the proxy type will not be a subclass of my specific class, and I will get a ClassCastException, correct?

It seems that I have three alternatives
1. Expose an API for every concrete class in my DAO
2. Turn off proxying / lazy loading in the class (which I don't know how to do with annotations).
3. Change my load method to use HQL to force the initial load.

Thanks for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 08, 2005 5:03 pm 
Regular
Regular

Joined: Thu Jul 08, 2004 1:21 pm
Posts: 68
Location: Recife - Pernambuco - Brazil
bblount wrote:
It seems that I have three alternatives
1. Expose an API for every concrete class in my DAO

This seems more correct to me. Anyway, you can use generics too, something like:
Code:
public class MyDao<T extends BaseClass> {
   public T get(Serializable id) {
      ...
   }

   public T save(T obj) {
      ...
   }
}

bblount wrote:
2. Turn off proxying / lazy loading in the class (which I don't know how to do with annotations).

Are you talking about it:
http://www.hibernate.org/hib_docs/annot ... Proxy.html

?

valeuz...

_________________
Marcos Silva Pereira
http://blastemica.blogspot.com


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