-->
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.  [ 4 posts ] 
Author Message
 Post subject: How to use a sequence in non-primery-property
PostPosted: Fri Jul 06, 2007 3:39 am 
Newbie

Joined: Sat Apr 07, 2007 6:53 am
Posts: 16
I would like use a sequence in order to get a value for a property (no primery-key). For example,

CREATE TABLE PRODUCT (
ID INTEGER NOT NULL,
SERIAL DEFAULT (nextVal of a sequence) NOT NULL,
...
PRIMERY KEY (ID)
);

When I create a product and call saveOrUpdate() method I need that serial is initialized with nextVal of a sequence. How I can do it?

Other form would be call nextVal of sequence manually, but I don't know how Can I do it?

Thanks for all in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 3:57 am 
Beginner
Beginner

Joined: Mon Nov 13, 2006 9:43 am
Posts: 30
Hi,

have you taken a look at http://www.hibernate.org/hib_docs/refer ... -generated ?

Not sure that this is exactly what we need, but sounds not bad.

Regards,

Giorgi


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 4:01 am 
Regular
Regular

Joined: Mon Mar 26, 2007 12:38 am
Posts: 119
Hi,
If you are comfortable using database triggers, here is one way.

i) mark the property as "generated"
<property name="serial" generated="insert" insert="false" update="false" />
ii) have a database trigger to populate the value into this column on insert.

That's it.
Hibernate ensures that,
i) this column is excluded from inserts and updates.
ii) a select for this property is done automatically on flush.

Further,
This issue has been discussed several times in the forum.
You can see if some of them are useful to you.

-------------------------------------------
Rate the reply if you find it helpful


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 4:04 am 
Beginner
Beginner

Joined: Mon Nov 13, 2006 9:43 am
Posts: 30
Hi,

... or you might can use formula ?

See http://www.hibernate.org/hib_docs/refer ... n-property

Something like

Code:
<property name="serial"
    formula="( SELECT nextVal of a sequence from DUAL)"/>


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