-->
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.  [ 22 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Hibernate and Inheritance
PostPosted: Fri Mar 05, 2004 11:35 am 
Beginner
Beginner

Joined: Wed Mar 03, 2004 9:44 am
Posts: 23
Location: Brasil
Hi delpouve, the HQL query "FROM Executive e WHERE e.company.id = 1" works fine, but the HQL Query "FROM Company c" return the exception from MySQL:

"Unknown column 'executives0_.CompanyId' in 'field list'"

[]s

Ary Junior


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 05, 2004 11:45 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
excuse me to insist but in company mapping file do you have
<set
name="executives"
table="Executive"
lazy="false"
inverse="true"
cascade="all"
sort="unsorted"
order-by="Nome ASC"
>
<key
column="CompanyId"
/>
<one-to-many
class="br.com.valoriza.imf.site.persistence.Executive"
/>
</set>
or
<set
name="persons"
table="Person"
lazy="false"
inverse="true"
cascade="all"
sort="unsorted"
order-by="Nome ASC"
>
<key
column="CompanyId"
/>
<one-to-many
class="br.com.valoriza.imf.site.persistence.Person"
/>
</set>


The first is wrong, you cannot do that this way


Top
 Profile  
 
 Post subject: Hibernate and Inheritance
PostPosted: Fri Mar 05, 2004 11:53 am 
Beginner
Beginner

Joined: Wed Mar 03, 2004 9:44 am
Posts: 23
Location: Brasil
Ok, I understood, but why query "FROM Executive e WHERE e.company.id = 1" works and query "FROM Company c" does not work when I uses the first mapping?

[]s

Ary Junior


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 05, 2004 11:59 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
the first uses the mapping many(person) to one (company) declared on the person mapping file
the second uses the one(company) to many(executives) declared on the company mapping file, which in your case is wrong


Top
 Profile  
 
 Post subject: Hibernate and Inheritance
PostPosted: Fri Mar 05, 2004 2:27 pm 
Beginner
Beginner

Joined: Wed Mar 03, 2004 9:44 am
Posts: 23
Location: Brasil
Then, when I will have a reference for a Company and want to get all executives I will have that to execute the query "FROM br.com.valoriza.imf.site.persistence.Executive e WHERE e.company.id = ?" instead execute the method getExecutives()? That is correct?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 05, 2004 3:12 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
yes you're right since you cannot have directly getExecutives() but only getPersons().
But maybe it could be usefull for you to implement a getExecutives()method which do the simple test isInstanceOf().... on person collection


Top
 Profile  
 
 Post subject: Hibernate and Inheritance
PostPosted: Fri Mar 05, 2004 3:27 pm 
Beginner
Beginner

Joined: Wed Mar 03, 2004 9:44 am
Posts: 23
Location: Brasil
I accept however I did not like. In any way thanks very much.

[]s

Ary Junior


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 22 posts ]  Go to page Previous  1, 2

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.