-->
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: Annotation "table per class" inheritance problem
PostPosted: Tue May 27, 2008 11:43 am 
Newbie

Joined: Tue May 27, 2008 11:21 am
Posts: 5
Hi all,

I 've got a problem trying to create a table per concrete class inheritance using annotation.

The generated sql for each concrete class does not use the table defined in the superclass (@Table). The class hierarchy is simple. RequestInboxItem is the superclass and has TradeRequestInboxItem as a subclass. Finally the V_REQUEST_INBOX is a view

Do you have any idea of what I am doing wrong? All details are included below

Regards,

Kostas

Hibernate version:
3.2.6ga
Mapped classes:
Code:
@Entity
@Proxy(lazy=false)
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Table(name = "V_REQUEST_INBOX")
@DiscriminatorColumn(name = "REQUEST_TYPE_ID", discriminatorType = DiscriminatorType.INTEGER)
public abstract class RequestInboxItem extends Request{

}

@Entity
@Proxy(lazy=false)
@DiscriminatorValue("0")
public class TradeRequestInboxItem extends RequestInboxItem{

}

Full stack trace of any exception that occurs (in hibernate tools log console):
2008-05-27 16:31:57,673 WARN Main Thread org.hibernate.util.JDBCExceptionReporter - SQL Error: 942, SQLState: 42000
2008-05-27 16:31:57,673 ERROR Main Thread org.hibernate.util.JDBCExceptionReporter - ORA-00942: table or view does not exist

Name and version of the database you are using:
Oracle
The generated SQL (show_sql=true):
Code:
0: com.[omitted].TradeRequestInboxItem
-----------------
select
  tradereque0_.REQUEST_ID as REQUEST1_156_,
  tradereque0_.COUNTRY_ISO_CODE as COUNTRY2_156_,
  tradereque0_.CREATED_TIMESTAMP as CREATED3_156_,
  tradereque0_.REQUEST_TYPE_ID as REQUEST7_156_,
  tradereque0_.REQUEST_STATUS_ID as REQUEST8_156_,
  tradereque0_.STATUS_NOTE as STATUS4_156_,
  tradereque0_.UPDATED_BY_COFF as UPDATED5_156_,
  tradereque0_.UPDATED_TIMESTAMP as UPDATED6_156_
from
  TradeRequestInboxItem tradereque0_brokeracco0_


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 27, 2008 1:04 pm 
Newbie

Joined: Tue May 27, 2008 11:21 am
Posts: 5
Hello people again!

I think I spotted the problem but I don't know how to solve it!

The problem lies on the Request superclass. Its class definition is included below:
Code:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Request implements Serializable{
}


So the class hierarchy is as follow:

Request --- table per class ---> RequestInbox --- single table ---> TradeRequestInboxItem

when I removed the "table per class" hierarchy and made the RequestInbox superclass, the "single table" inheritance worked correctly.

Do you know if it is possible to use both inheritance type in the same class hierarchy? How can I do it?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 27, 2008 4:12 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
I have a nice little tutorial on performing inheritance mapping with Hibernate and JPA annotations, but each example, be it SINGLE_TABLE, TABLE_PER_CLASS, or JOINED types, does not mix inheritance types. :(

Image

Here's a brief Hibernate tutorial on mapping inheritance with JPA annotations:

http://www.thebookonhibernate.com/HiberBookWeb/learn.jsp?tutorial=16mappinginheritancewithjpa

For perhaps some more information on mapping inheritance with Hibernate, check out the Hibernate documenation:

http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#inheritance

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Last edited by Cameron McKenzie on Tue Jun 17, 2008 5:05 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed May 28, 2008 4:38 am 
Newbie

Joined: Tue May 27, 2008 11:21 am
Posts: 5
I think that it is possible to mix different inheritance strategies in a class hierarchy.

The hibernate reference documentation (http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#inheritance) describes two ways:
9.1.4. Mixing table per class hierarchy with t[b]able per subclass and
9.1.7. Mixing implicit polymorphism with other inheritance mappings

I would like to use the second one (Mixing implicit polymorphism with other inheritance mappings) but I dont know how to do it using annotations.

Any ideas?

Regards,

Kostas


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.