-->
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.  [ 3 posts ] 
Author Message
 Post subject: Polymorphism in hibernate inheritance model
PostPosted: Wed Aug 24, 2011 4:36 am 
Newbie

Joined: Wed Aug 24, 2011 4:25 am
Posts: 1
Hello, let's assume that we have a certain situation where class A is parent for class B and class C. Inheritance strategy should be irrelevent.

Is there any way to select only instances of class A without unnecessary joins/unions with children classes seen in hibernate-generated sql query?

As I understand specifying explicit polymorphism on entities will cause selection of B or C without parent properties from A. But how to reverse this process maintaining hibernate inheritance model?

Thanks in advance


Top
 Profile  
 
 Post subject: Re: Polymorphism in hibernate inheritance model
PostPosted: Wed Aug 24, 2011 5:31 am 
Newbie

Joined: Tue Jul 19, 2011 2:16 pm
Posts: 19
I actually have the same problem... Select only the parent class... (I have posted in the frenche forum : viewtopic.php?f=11&t=1012351)

I use Spring and hibernateTemplate.
I try the following, but it don't work :
Code:
DetachedCriteria criteria = DetachedCriteria.forClass(PlanSystem.class);
criteria.add(Restrictions.eq("class", PlanSystem.class))


Top
 Profile  
 
 Post subject: Re: Polymorphism in hibernate inheritance model
PostPosted: Thu Aug 25, 2011 10:52 am 
Newbie

Joined: Thu Aug 25, 2011 10:31 am
Posts: 1
We figured out solution:

Code:
@MappedSuperclass
class abstractA {
//all common props
}

@Entity
@Table(name="tableA")
class FakeA {
// nothing
}


@Entity
@Inheritance(str = JOIN)
@Table(name="tableA")
class A{
// nothing
}

@Entity
@Table(name="tableB")
class B{
// additiona props only from tableB
}

@Entity
@Table(name="tableC")
class C{
// additiona props only from tableC
}


you can search by FakeA .class (without any join), B.class, C.class... etc.

This is not a pretty solution, but it works !


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