-->
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.  [ 9 posts ] 
Author Message
 Post subject: Inheritance problem
PostPosted: Fri Nov 11, 2005 5:18 am 
Newbie

Joined: Tue Feb 01, 2005 5:04 am
Posts: 8
Location: Barcelona
I'm using the version 2.1.8 of Hibernate.

- I have a class A with a list of B's.
- B is an abstract class and some concrete classes B1, B2, B3,... extend it.
- B's are mapped using a table per class hierarchy.

The problem is that A doesn't know all B's implementations and in some situations I don't need to load all B's concrete classes(I don't use all mappings), but the data exists in the database so I get the exception cannot instantiate an abstract class or interface ...

Is there a way to avoid this error and only to load the instances he knows?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 11, 2005 7:39 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
You can either use
Code:
where="arbitrary sql where condition"

in the class mapping to filter out some discriminator values which should never be read by hibernate, or use dynamic filters, see chapter 18 of the reference manual.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 11, 2005 8:06 am 
Newbie

Joined: Tue Feb 01, 2005 5:04 am
Posts: 8
Location: Barcelona
The problem is that sometimes I start with all mappings and sometimes with a subset of them.

So I don't know the other types to exclude them filtering the datas.

Thanks,


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 11, 2005 12:45 pm 
Newbie

Joined: Tue Feb 01, 2005 5:04 am
Posts: 8
Location: Barcelona
I'm using the strategy table per subclass


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 12, 2005 3:56 pm 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Hi Josep

Instead of filtering the ones you don't want (and don't know) you could of course ask for the ones you want (and hopefully know).

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 3:23 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Gues this is what you're realy looking for

Code:
from Cat cat where cat.class = DomesticCat


See chapter 15.7 of the reference manual.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 5:37 am 
Newbie

Joined: Tue Feb 01, 2005 5:04 am
Posts: 8
Location: Barcelona
Hi Ernst
I will try, but I need Hibernate 3 isn't it? So I have to migrate my mappings firts.

I have:
- A class CL1 wich has a list of CL2.
- CL2 is an abstract class in order to extend adding new behaviours not yet known.
- I have concrete CL2 classes CL2-1,CL2-2, ...
- Each class (CL2, CL2-1,...) maps to a table.
- Another user wil add CL2-x concrete classes and its new mappings.
- When the system starts will load all the mappings indicated.
- If I want to get the list of CL2 that an instance of CL1 has, I do it with a simple get method returning a List.
-The problem arises when in the database the table TCL2 has registers that are mapping CL2-2 instances and I'm not using these mappings.

In this situation, where you suggest to put this filter?

Thanks,


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 4:54 pm 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
According to the docs in chapter 11.7. The where clause the special property class is available in H2 as well.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 01, 2005 8:00 am 
Newbie

Joined: Tue Feb 01, 2005 5:04 am
Posts: 8
Location: Barcelona
Thanks Ernst,

I've been so busy with another thing.
I've migrate to hibernate 3 and I've solved it with the new inheritance mapping table per concrete class (union-class)


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