-->
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: sequence number help
PostPosted: Thu Feb 02, 2006 10:26 pm 
Newbie

Joined: Thu Feb 02, 2006 10:14 pm
Posts: 2
hi to all,

i need help in generating a sequence number for one of my property in my hibernate-mapping.. i tried to use the attribute "generated" but hibernate encounters error.

here's the log:
2006-02-03 10:12:54,437~DEBUG~com.jbhunt.biz.assets.fuel.automated.core.util.BeanFactoryLoader~ Start configure(path)
2006-02-03 10:12:54,578~DEBUG~com.jbhunt.biz.assets.fuel.automated.core.util.BeanFactoryLoader~ End configure(path)
2006-02-03 10:12:54,890~ERROR~org.hibernate.util.XMLHelper~ Error parsing XML: XML InputStream(25) Attribute "generated" must be declared for element type "property".
2006-02-03 10:12:54,890~ERROR~org.hibernate.util.XMLHelper~ Error parsing XML: XML InputStream(25) Attribute "generated" must be declared for element type "property".

here's the excerpt of my hibernate mapping:
<id name="fuelPurchaseRequestId"
column="FL_PUR_REQ_I" type="integer" unsaved-value="null">
<generator class="sequence" >
<param name="sequence">FL_PUR_REQ_I_SEQ</param>
</generator>
</id>
<property name="purchaseOrderNumberPrefix"
column="PO_PFX" type="com.jbhunt.biz.assets.fuel.automated.core.util.TrimmedString"
not-null="false" unique="false" update="true" insert="true"
optimistic-lock="true" lazy="false"/>
<property name="purchaseOrderNumber"
column="PO_NBR" type="integer"
not-null="false" unique="true" update="true" insert="true"
optimistic-lock="true" lazy="false" generated="insert"/>


is there any other way on how i can generate a sequence no. for the property "purchaseOrderNumber"

any suggestionS?

thanks in advance! =)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 02, 2006 10:46 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
There's isn't a "generated" attribute, hence the exception.

Do you just want a read-only value that the database is looking after? It doesn't look like it, seeing as you have insert="true" update="true": those sorts of columns are usually set up with false for both insert and update.

If you want a number that your code will generate, you have to implement that yourself. Hibernate will handle it if it's an id field, but not for standard properties.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 02, 2006 11:15 pm 
Newbie

Joined: Thu Feb 02, 2006 10:14 pm
Posts: 2
hi,

i still need to insert and update records to the database through its sequence no.

any reference on how i can implement a type that could generate id through the sequence id in the database..

thanks!!!!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 02, 2006 11:50 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Making one column insert false and update false does not mean that you can't create/edit rows, it just means that hibernate won't touch that column. It will only read from it. So if the DB is generating the value in that column, you do want to set insert and update to false.

If the value is changed only on insert, then you should refresh an object after saving it for the first time. If the value changes every time the row is edited, then you should refresh the object after every commit.

As an aside, why have you got two DB-generated sequences in one table? Why not use the row ID as your order number?


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.