-->
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.  [ 1 post ] 
Author Message
 Post subject: How do I override a sequence generator?
PostPosted: Tue Feb 15, 2005 9:35 am 
Beginner
Beginner

Joined: Mon Nov 22, 2004 11:21 am
Posts: 42
How do I override a sequence generated PK identifier in the example below? The two subclasses below are mutual exclusive. AFAIK I have to delete the old "Checkdomain" object to turn it to a "Checkmaxlength" object. I would like to keep the old PK value for the new object.

Please help, I need to clarify this urgently.

Hibernate version:
2.1.8

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping package="com.abc">
<class name="Checkformat" table="CHECKFORMAT">
<id
column="ID"
name="Id"
type="integer"
>
<generator class="sequence">
<param name="sequence">GEN_CHECKFORMAT_ID</param>
</generator>
</id>
<property
column="COMMENT"
length="1000"
name="Comment"
not-null="false"
type="string"
/>

<joined-subclass name="Checkdomain" table="CHECKDOMAIN">
<key column="ASSIGNMENTID" />
<property
column="MAXVALUE"
length="10"
name="Maxvalue"
not-null="true"
type="integer"
/>
<property
column="MINVALUE"
length="10"
name="Minvalue"
not-null="true"
type="integer"
/>
</joined-subclass>
<joined-subclass name="Checkmaxlength" table="CHECKMAXLENGTH">
<key column="ASSIGNMENTID" />
<property
column="MAXLENGTH"
length="5"
name="Maxlength"
not-null="true"
type="java.lang.Short"
/>
</joined-subclass>
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Code:
Transaction trans = session.beginTransaction();
Checkdomain cfd = new Checkdomain();
cfd.setComment("My new Checkformat");
cfd.setMaxvalue(10);
cfd.setMinvalue(2);
Integer id = (Integer) session.save(cfd);

// Now the user decides to change the data to Checkmaxlength.
// Maybe even later in a different transaction.
CheckmaxLength cml = new Checkmaxlength();
cml.setId(id);
cml.setComment(cfd.getComment());
cml.setMaxlength(100);

// Since both objects are subclass of Checkformat, we have to delete
// the old object in order to add the new one
// (these role tables are mutual exclusive)
session.delete(cfd);
session.save(cml);

trans.commit();


Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

[/code]

_________________
Real programmers confuse Halloween and Christmas because OCT 31 = DEC 25


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.