-->
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.  [ 3 posts ] 
Author Message
 Post subject: new on Hibernate
PostPosted: Mon Nov 27, 2006 5:27 pm 
Newbie

Joined: Mon Nov 27, 2006 4:18 pm
Posts: 1
Hi Guys,

I am new to hibernate, using version 3.2/DB - oracle 10g

I have a quick question - I need to insert a new record in a table. The table has a primary key - with the generator for this key set to a sequence.

The table has another column which needs to be generated from a sequence, only if that object field is 0. Right now I have that logic sitting in my DAO. I was wondering if theres a better or hibernate way of doing this....like putting this in a hbm.xml file ???


if (dataObject.getSomeId() == null || dataObject.getSomeId().longValue() <= 0) {
SQLQuery query = session.createSQLQuery("select DATA_SEQ.nextval from DUAL");
Number number = (Number) query.uniqueResult();
dataObject.setSomeId(new Long(number.longValue()));
}//end if

// insert new record
Object object = session.save(dataObject);


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 27, 2006 6:30 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
You could use a DB trigger.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 6:29 am 
Senior
Senior

Joined: Mon Oct 23, 2006 5:12 am
Posts: 141
Location: Galicia, Spain
Or if you want to do everything in the code, use

org.hibernate.Interceptor.onSave()

_________________
andresgr (--don't forget to rate)


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