-->
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: Hibernate's generator
PostPosted: Sat Apr 01, 2006 9:13 am 
Newbie

Joined: Tue Mar 28, 2006 11:32 am
Posts: 3
Location: India
Can we have the option to use Hibernate's generator capability on other field of table since that can only be used for identifier columns and there is already an identifier column defined for this table ?

In below mapping file, there is directShipOrderId which is associated with generator class (Italic), I want to make directShipOrderNumber (bold)autoincremented e.g. A0000001, A0000002... so on.



<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping>
<!--
Created by Persistence Tool
-->

<class
name="com.abn.wppaup.shared.domain.DirectShipOrderDO"
table="DIRECT_SHIP_ORDER"
lazy="false"
>
<meta attribute="implement-equals">true</meta>

<id
name="directShipOrderId"
type="java.lang.Integer"
column="DIRECT_SHIP_ORDER_ID"
>
<generator class="sequence">
<param name="sequence">direct_ship_order_seq</param>
</generator>
</id>

<property
name="directShipOrderNumber"
type="java.lang.String"
column="DIRECT_SHIP_ORDER_NUMBER"
access="field"
not-null="true"
length="10"
>
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
</property>


</hibernate-mapping>
</class>

Pointers are most welcome.

_________________
Tushar Gorde
IBM India Pvt Ltd.
Hyderabad - India


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 02, 2006 6:57 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
No, generator is id only. You can let the database generate the value in the normal way (insert trigger, sequence, etc.) and specify insert="false" update="false" on the mapping: that will accomplish what you're looking for. Note that you'll have to refresh() each object after you save it for the first time, so that the DB-generated field is loading into the java object.


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.