-->
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: Troubles with InheritanceType.JOINED
PostPosted: Tue Apr 29, 2008 3:47 am 
Newbie

Joined: Thu Feb 16, 2006 4:16 am
Posts: 17
Location: Austria
Hello community!

I've got interesting troubles with inheritance. The type of inheritance is JOINED.

Hibernate version:
3.2.4 SP1

Name and version of the database you are using:
Ingres 9.0.4

Here is the description of my troubles. I've got different TodoList entries which inherit a baseclass.

The base class looks like:
Code:
@Entity
@org.hibernate.annotations.Entity(dynamicUpdate = true)
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "uptoip_todo", schema = "ingres", uniqueConstraints = {})
public class UptoipTodo implements java.io.Serializable
{
  [...]


The child classes look like:

1. TodoProject
Code:
@Entity
@org.hibernate.annotations.Entity(dynamicUpdate = true)
@Table(name = "uptoip_todo_project", schema = "ingres")
public class UptoipTodoProject extends UptoipTodo
{
  [...]


2. TodoIpRight
Code:
@Entity
@org.hibernate.annotations.Entity(dynamicUpdate = true)
@Table(name = "uptoip_todo_ip_right", schema = "ingres")
public class UptoipTodoIpRight extends UptoipTodo
{
  [...]


Apparently there is no difference between the child classes. Only the member variables are different. I guess this should not have any consequences.

With this query I trie to load the different TodoList entries.
Code:
em.createQuery("FROM UptoipTodo u WHERE u.resolveUser is null");


The test data is available for every TodoList entry (baseclass and child-class). The query delivers results for each query.

BUT: If the TodoList entry is from type TodoProject Hibernate can't deliver enough information. It is not able to distinguish between TodoProject and UptoipTodo. It delivers only UptoipTodo classes although it is definitively from type UptoipProject. I guess Hibernate loses the inheritance information on the way.

Finally: Hibernate is able to deliver the inheritance-structure (base-class and child-class) not in all ways. Once it works and sometimes it does not work.

I hope that there is anyone who could give me some hints to solve the problem.

Best regards,
Alex


Top
 Profile  
 
 Post subject: Discriminator
PostPosted: Tue Apr 29, 2008 6:06 pm 
Senior
Senior

Joined: Sun Jun 11, 2006 10:41 am
Posts: 164
It doesn't look like you declared a @DiscriminatorColumn and @DiscriminatorValue. pls look them up in JEE tutorial for more info and let me know if it helped.
thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 30, 2008 4:45 am 
Newbie

Joined: Thu Feb 16, 2006 4:16 am
Posts: 17
Location: Austria
Hi,

I read tutorials and found out that the DiscriminatorValue resp the DiscriminatorColumn are only for usage with Single Table per Class Hierarchy (InheritanceType.SINGLE_TABLE).

Although this hint was not the solution of my troubles it directed my point of view to the @PrimaryKeyJoinColumn.

In spite of the fact that it is not necessary I tried out the PrimaryKeyJoinColumn. It is not necessary because the IDs have the same name - but it does not work, too.

Anyway, thanks for your response. By the way, I hope that there is anyone who could help me.

Thanks in advance!

Best regards,
Alex


For better illustration I'll give you an overview of my tables:

Code:
CREATE TABLE uptoip_todo
(
   id INTEGER PRIMARY KEY not null,
   errorcode_id INTEGER,
   errormsg VARCHAR(100),
   creation_date DATE,
   resolve_user INTEGER,
   resolve_date DATE
);
[...]

CREATE TABLE uptoip_todo_project
(
   id INTEGER PRIMARY KEY not null,
   project_id INTEGER not null
);
ALTER TABLE uptoip_todo_project
ADD CONSTRAINT fk_uip_todoprj_uip_todo
FOREIGN KEY (id)
REFERENCES uptoip_todo(id) ON DELETE CASCADE ON UPDATE CASCADE;
[...]

CREATE TABLE uptoip_todo_ip_right
(
   id INTEGER PRIMARY KEY not null,
   ip_right_id INTEGER not null,
   rf_due_date_id INTEGER
);
ALTER TABLE uptoip_todo_ip_right
ADD CONSTRAINT fk_uip_todoipr_uip_todo
FOREIGN KEY (id)
REFERENCES uptoip_todo(id) ON DELETE CASCADE ON UPDATE CASCADE;
[...]


Last edited by ameisinger on Wed Apr 30, 2008 7:25 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: deja vu
PostPosted: Wed Apr 30, 2008 5:09 am 
Senior
Senior

Joined: Sun Jun 11, 2006 10:41 am
Posts: 164
I ask again: did you try using a discriminator? the JEE tutorial I mentioned reads:

"Some Java Persistence API providers, including the default provider in the Application Server, require a discriminator column in the table that corresponds to the root entity when using the joined subclass strategy. If you are not using automatic table creation in your application, make sure the database table is set up correctly for the discriminator column defaults, or use the @DiscriminatorColumn annotation to match your database schema. "

My project uses discriminators and I'm perfectly capable of querying for baseclasses, subclasses, etc.


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.