-->
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.  [ 1 post ] 
Author Message
 Post subject: Identity Column and Hibernate
PostPosted: Mon Nov 28, 2005 4:33 pm 
Newbie

Joined: Mon Nov 28, 2005 12:32 pm
Posts: 3
Background Info:
Hibernate 2.1.6
Database MS SQL Server

Domain Model:
xxxDeal (has primary key called internal_id of type varchar (36)) extends Deal

Mapping file for xxxDeal:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>

<joined-subclass extends="com.abc.def.model.Deal"
name="com.abc.ghi.def.model.xxxDeal"
table="XXX_DEAL"
>
<key column="INTERNAL_ID"/>

<property
name="agreementId"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="AGREEMENT_ID"
/>


<property
name="refDealId"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="REF_DEAL_ID"
/>

<property
name="agreementType"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="AGREEMENT_TYPE"
/>

<property
name="autoCreated"
type="boolean"
update="true"
insert="true"
access="property"
column="AUTO_CREATED"
/>

</joined-subclass>

</hibernate-mapping>

Problem Statement:
Need to create a new column called ERP_ID (max size of 10) which is an identity column or a column with a uniqueidentifier (varchar(10)) that gets generated by the Database.

Approaches:
1] Tried to create an <id> attribute in the mapping file but of course this is not allowed as I can only have one id mapped to the hbm file.

2] <property
name="erpId"
type="java.lang.String"
access="property"
column="ERP_ID"
length="9"
update="false"
insert="true"
formula="?"
/>

is the approach I think will be good. I am just not sure what formula would be best to generate a uniqueidentifier.

Question:
Is there any way in Hibernate to specify a column of type identity (MSSQL server) that gets generated by the DB and is not the primary key or identity column?

Are there any suggestions on different approaches?

Any suggestions on the formula?

Anyone ever done something similar?

thanks and any responses are appreciated.

-a


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.