-->
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: inheritance InheritanceType.JOINED derived properties null
PostPosted: Fri Mar 16, 2007 3:31 pm 
Newbie

Joined: Fri Mar 02, 2007 5:59 pm
Posts: 3
Location: Denver, CO
I have a similar issue. I have a parent table with several child tables. Subcomponent is the parent. Term is one of the children. The parent and the children all have a CREATED_DATE column.

Two tables:
--------------------------
SUBCOMPONENT
--------------------------
SUBCOMPONENT_ID (PK)
SUBCOMPONENT_TYPE
CREATE_DATE
--- more columns

--------
TERM
--------
SUBCOMPONENT_ID (PK) (FK)
CREATE_DATE
--- more columns

Code:
@Entity
@Table(name = "PRM_SUBCOMPONENT")
@Inheritance(strategy = InheritanceType.JOINED)
public class Subcomponent implements Serializable  {
Date createdDate
...
}

@Entity
@Table(name = "PRM_TERM")
@PrimaryKeyJoinColumn(name = "SUBCOMPONENT_ID")
@DiscriminatorColumn(name = "SUBCOMPONENT_TYPE", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue("TERM")
public class Term extends Subcomponent implements Serializable {
...
}


Now if I do the following:
Code:
Subcomponent subcomponent = new Subcomponent();
subcomponent .setCreatedDate(new Date);
...
subcomponent Dao.save(subcomponent );

Term term = new Term();
term.setCreatedDate(new Date);
...
termDao.update(term);


the subcomponent persists fine, but and the term starts saving correctly (I see that Hibernate first INSERTS a subcomponent and then a term but I get a SQL exception: cannot insert NULL into ("PRM"."PRM_TERM"."CREATED_DATE")

The work around I've found is to define a new field in the Term class called termCreatedDate and map that to the CREATED_DATE column on the PRM_TERM table. This seems to defeat the purpose of using inheritance. I'm using Hibernate 3.2.2 (latest version) as the JPA provider. Any ideas anyone?

Hibernate version:
3.2.2

Mapping documents:

Name and version of the database you are using:
Mysql 5.0.X

The generated SQL (show_sql=true):
2007-03-16 13:26:19,110 [main] DEBUG org.hibernate.SQL - insert into PRM_SUBCOMPONENT (SUBCOMPONENT_TYPE, SUBCOMPONENT_ID, more columns...) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

2007-03-16 13:26:19,110 [main] DEBUG org.hibernate.SQL - insert into PRM_TERM (SUBCOMPONENT_ID, more columns...) values (?, ?, ?, ?)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 19, 2007 9:01 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Using 2 CREATE_DATE columns seems to defeat the purpose of your normalized DB model, this issue just leaks to your object model.

_________________
Emmanuel


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.