-->
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.  [ 6 posts ] 
Author Message
 Post subject: Extending tables in Hibernate 3
PostPosted: Tue Sep 05, 2006 5:08 pm 
Newbie

Joined: Tue Sep 05, 2006 4:50 pm
Posts: 3
We're having a problem with extending tables in Hibernate 3 (where in Hibernate 2 everything worked fine.)

Using Hiberante 2 we had 2 tables, one extending the other. The tables in question were:

NOTIFICATIONS

NOTIFICATIONID BIGINT NO DEFAULT YES(1,1)
CREATED TIMESTAMP YES
ACTIONID INTEGER YES
OBJECTID BIGINT NO
OBJECTTYPE INTEGER NO
RECIPIENT VARCHAR 50 YES
CREATOR VARCHAR 50 YES
MESSAGE VARCHAR 255 YES
TYPE SMALLINT NO

Which was extended by

NOTIFICATIONSHISTORY

NOTIFICATIONID BIGINT NO
DELETEDBY VARCHAR 255 YES
DATEDELETED TIMESTAMP YES

The hbm file definitions for each table were as follows:

the hbm for the NOTIFICATIONS is:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping
>
<class
name="com.bps.iproject.domain.notification.Notification"
table="Notifications"
polymorphism="explicit"
optimistic-lock="none"
>
<cache usage="nonstrict-read-write" />

<id
name="id"
column="NotificationId"
type="long"
unsaved-value="-1"
>
<generator class="native">
</generator>
</id>

<property
name="created"
type="timestamp"
update="true"
insert="true"
column="Created"
/>

<property
name="actionId"
type="int"
update="true"
insert="true"
column="ActionId"
/>

<component
name="objectPointer"
class="com.bps.iproject.domain.DomainObjectPointer"
>
<property
name="objectId"
type="long"
update="true"
insert="true"
column="ObjectId"
not-null="true"
/>

<property
name="objectType"
type="int"
update="true"
insert="true"
column="ObjectType"
not-null="true"
/>

</component>

<property
name="recipient"
type="java.lang.String"
update="true"
insert="true"
column="Recipient"
length="50"
/>

<property
name="creator"
type="java.lang.String"
update="true"
insert="true"
column="Creator"
length="50"
/>

<property
name="message"
type="java.lang.String"
update="true"
insert="true"
column="Message"
length="255"
/>

<property
name="type"
type="com.bps.iproject.dao.notification.impl.NotificationUserType"
update="true"
insert="true"
column="Type"
not-null="true"
/>
</class>

</hibernate-mapping>



and the hbm for the NOTIFICATIONSHISTORY is:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping
>
<class
name="com.bps.gs.sox.domain.notification.NotificationHistory"
table="NotificationsHistory"
polymorphism="explicit"
optimistic-lock="none"
>
<cache usage="nonstrict-read-write" />

<id
name="id"
column="NotificationId"
type="long"
unsaved-value="-1"
>
<generator class="assigned">
</generator>
</id>

<property
name="deletedBy"
type="java.lang.String"
update="true"
insert="true"
column="Deletedby"
length="255"
/>

<property
name="dateDeleted"
type="timestamp"
update="true"
insert="true"
column="Datedeleted"
/>

<property
name="created"
type="timestamp"
update="true"
insert="true"
column="Created"
/>

<property
name="actionId"
type="int"
update="true"
insert="true"
column="ActionId"
/>

<component
name="objectPointer"
class="com.bps.iproject.domain.DomainObjectPointer"
>
<property
name="objectId"
type="long"
update="true"
insert="true"
column="ObjectId"
not-null="true"
/>

<property
name="objectType"
type="int"
update="true"
insert="true"
column="ObjectType"
not-null="true"
/>

</component>

<property
name="recipient"
type="java.lang.String"
update="true"
insert="true"
column="Recipient"
length="50"
/>

<property
name="creator"
type="java.lang.String"
update="true"
insert="true"
column="Creator"
length="50"
/>

<property
name="message"
type="java.lang.String"
update="true"
insert="true"
column="Message"
length="255"
/>

<property
name="type"
type="com.bps.iproject.dao.notification.impl.NotificationUserType"
update="true"
insert="true"
column="Type"
not-null="true"
/>
</class>

</hibernate-mapping>

This doesn't work in Hibernate 3. What I'm having trouble with is how to get the same table structure where the extended table only contians the NotificationId field (the fk to the Notifications table) and the extended fields. Currently when we try to run our code we get an exception saying:

could not resolve property: recipient of: com.bps.gs.sox.domain.notification.NotificationHistory

I've found a few different ways to structure things, but what I'm looking for is the proper way to set this up that won't require a data migration script to move data into a new table structure. Any help would be greatly appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 05, 2006 5:28 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
so does your class actually have that property ? and is it in the classpath ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 06, 2006 11:19 am 
Newbie

Joined: Tue Sep 05, 2006 4:50 pm
Posts: 3
max wrote:
so does your class actually have that property ? and is it in the classpath ?


Sorry I should clarify, we use xdoclet to generate the hbm files. Now under Hibernate 3 the hbm file the history table looks like this:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping
>
<class
name="com.bps.gs.sox.domain.notification.NotificationHistory"
table="NotificationsHistory"
polymorphism="explicit"
optimistic-lock="none"
>
<cache usage="nonstrict-read-write" />

<id
name="id"
column="NotificationId"
type="long"
unsaved-value="-1"
>
<generator class="assigned">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-NotificationHistory.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>

<property
name="deletedBy"
type="java.lang.String"
update="true"
insert="true"
column="Deletedby"
length="255"
/>

<property
name="dateDeleted"
type="timestamp"
update="true"
insert="true"
column="Datedeleted"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-NotificationHistory.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>


And of course I get the exception I mentioned in my original post. When I put in the fields from the parent table into the hbm file, (the way the hbm file looked when generated under Hibernate 2 - see my original post) the NotificationsHistory table now duplicates those fields from the parent Notifications table in the database.

I'm looking for an understanding of what the hbm for the NotificationsHistory table needs to look like so that I don't need to change the table structure. (Our app is in production so changing the database would require a migration script.)

How do I avoid this and get the same behaviour I had before.

cheers,
Marc


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 06, 2006 2:33 pm 
Newbie

Joined: Tue Sep 05, 2006 4:50 pm
Posts: 3
Okay one more clarification of my problem. (And at this point I'll apologize for the unclear manner in which I first posed my question.)

Upon further review it appears that our problem is strictly related to how xdoclet generates our hbm file for the NotificationHistory table. I was incorrect about the NotificationsHistory in our current build, it does contain all the fields of the Notifications table plus the additional fields. Our problem is that without having getters for the parent class fields on the NotificationHistory.java class the generated hbm file now doesn't include those fields (where before it did) and the NotificationsHistory table isn't built properly.

Does anyone know why this is different in Hiberante 3.

Thanks,
Marc


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 06, 2006 2:47 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
your issue is with xdoclet generation, not hibernate 3.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 06, 2006 7:11 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
What version of Xdoclet?

It does behave differently depending on the version number - possible a bug but it would be a very easy fix.


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