-->
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.  [ 2 posts ] 
Author Message
 Post subject: Possible bug in mixing inheritance strategies 3.5
PostPosted: Tue Apr 27, 2010 12:56 pm 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
Hi,

I'm trying out the mixing of inheritance and I'm running into a situation that I think may be a bug.

I have the following classes
Code:
@Entity
@Table(name = "Animal")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorValue(value = "AML")
public class Animal{
   @Column
   private int eyes = 2;
}

@Entity
@DiscriminatorValue(value = "CAT")
public class Cat extends Animal{
   @Column
   boolean purs = true;
}

@Entity
@DiscriminatorValue("ELF")
@SecondaryTable(name="Elefant",   pkJoinColumns =
   {
      @PrimaryKeyJoinColumn(name = "animalId", referencedColumnName = "animalId")
   }
)
public class Elefant extends Animal{
   @Column
   boolean protected = true;
}


I run the following query
Code:
DetachedCriteria dc = DetachedCriteria.forClass(Animal.class);
dc.add(Restrictions.eq("eyes", new Integer(2)));
List<Animal> result = getHibernateTemplate().findByCriteria(dc);


I get an error that sais
Unknown column 'this_.protected'

When I review the query, I see that it looks like this

select
this_.eyes,
this_.purs,
this_.protected
from
Animal this_
left outer join
Elefant this_1_
on this_.animalID=this_1_.animalId
where this_.eyes =2;

What I would expect to see is
select
this_.eyes,
this_.purs,
this1_.protected
from
Animal this_
left outer join
Elefant this_1_
on this_.animalID=this_1_.animalId
where this_.eyes =2;

Can anyone enlighten me on either bug or stupidity on my side?

Kind regards,

Marc


Top
 Profile  
 
 Post subject: Re: Possible bug in mixing inheritance strategies 3.5
PostPosted: Tue Apr 27, 2010 3:44 pm 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
As it turns out: no bug.

What you need to do is specify the target table on each Column specification with each entity that has a secondaryTable specified

Code:
@Column(table="Elefant")


So, if you're in the business of storing Elefants. You're ood to go.

Marc


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