-->
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: New column, default value, using xdoclet
PostPosted: Fri Oct 01, 2004 7:20 am 
Beginner
Beginner

Joined: Fri Oct 01, 2004 7:13 am
Posts: 20
Hibernate version: 2.13



I have added a new field to my table which is to be unique, but for new records I would like the new column to take the value of the generated id column as a default. I can update the existing data when I make the schema change, but would like to cover the creation of new records and don't think I can get the id in the constructor.

/**
* @hibernate.id generator-class="sequence"
* @return
*/
public long getId()
{
return id;
}

Is this possible please?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 01, 2004 11:44 am 
Beginner
Beginner

Joined: Fri Oct 01, 2004 7:13 am
Posts: 20
I would like to set another field to use the property of the id field as a default, but is this possible as the id field will only be determined by the sequence at write time?

Any ideas, how best to achieve this please.

I do not really want to write a trigger at the db level, but can't think of anything else currently.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 02, 2004 1:33 pm 
Beginner
Beginner

Joined: Fri Oct 01, 2004 7:13 am
Posts: 20
Someone must have run into this situation before and not wanted to install a db trigger?

Any ideas to a hibernate way?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 04, 2004 12:36 pm 
Senior
Senior

Joined: Wed Aug 27, 2003 4:08 am
Posts: 178
Location: Wiesbaden, Germany
You can change your ID setter to propagate id value to
another property if this is still null ( not set )

_________________
Got new hibernate xdoclet plugin? http://www.sourceforge.net/projects/xdoclet-plugins/
... Momentan auf der Suche nach neuen Projekt ode Festanstellung....


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 05, 2004 12:10 pm 
Beginner
Beginner

Joined: Fri Oct 01, 2004 7:13 am
Posts: 20
Thanks for your reply.

Will adding some code in the setId() method work seeing as the Id is based on a sequence?

I'll try this out, and see what happens.

Cheers


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 05, 2004 12:11 pm 
Senior
Senior

Joined: Wed Aug 27, 2003 4:08 am
Posts: 178
Location: Wiesbaden, Germany
cam292 wrote:
Thanks for your reply.

Will adding some code in the setId() method work seeing as the Id is based on a sequence?

I'll try this out, and see what happens.

Cheers


I guess so. AFAIR, hibernate first sets id and then saves object -
could work. BUt if I were you, I would place System.err.println()
into set id just to be sure...

_________________
Got new hibernate xdoclet plugin? http://www.sourceforge.net/projects/xdoclet-plugins/
... Momentan auf der Suche nach neuen Projekt ode Festanstellung....


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.