-->
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: Generated values in Hibernate
PostPosted: Fri Feb 08, 2013 6:32 am 
Newbie

Joined: Tue Dec 04, 2012 6:10 pm
Posts: 2
I have a column in my table that is mapped like this in the model object:

Code:
@Generated(GenerationTime.INSERT)
@Column(name = "other_id", nullable = false, unique = false, insertable = true, updatable = false)
private Long other;


While most of the times I want to use the generated value, there are times where I want to assign a value to this column manually. Is this possible? I tried to give a value to the column from the setter method, however this is being overwritten on insert.


Top
 Profile  
 
 Post subject: Re: Generated values in Hibernate
PostPosted: Mon Feb 11, 2013 8:19 am 
Beginner
Beginner

Joined: Wed Feb 06, 2013 2:43 am
Posts: 46
You can do this by extending the Sequence Generator and overriding the generate column.
Let me know if you need more help on this.

public class CustomSequenceGenerator extends SequenceGenerator {

@Override
public Serializable generate(SessionImplementor session, Object obj)
throws HibernateException {

// Implmentation according to need.
}
}

_________________
Thanks,
Ajit Singh
ajits@mindfiresolutions.com
www.mindfiresolutions.com


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.