-->
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.  [ 5 posts ] 
Author Message
 Post subject: SQL Server identity not generated in the Mapping Files
PostPosted: Mon Jun 15, 2009 11:41 am 
Newbie

Joined: Mon Jun 15, 2009 10:51 am
Posts: 4
Hello,

I am using SQL Server 2005. I am generating the Mapping Files and Domain Objects using the Eclipse Hibernate Code Generation Tools through Hibernate Plugin for the Eclipse.Almost all my tables have the identity type Primary Key. But in the .hbm.xml files generated, it is not reflected. I see <generator class="assigned"> in the generated Mapping files. I had to change all the generated Mapping Files to point it to identity. I have to do this everytime I generate the Mapping Files. Is this a bug in Hibernate/Hibernate tools of Eclipse? Did anyone face this problem. Am I doing something wrong? Some body please reply me if you have any idea of the issue.

Thanks,
Leela


Top
 Profile  
 
 Post subject: Re: SQL Server identity not generated in the Mapping Files
PostPosted: Tue Jun 16, 2009 8:11 am 
Regular
Regular

Joined: Wed Jun 20, 2007 1:53 am
Posts: 75
There are lot of generator class like assigned, increment (this require sequence name if DB is Oracle), etc., I think there is no way for Hibernate to identify this generator class from database schema, somehow we have to instruct it in the tool. can you post one of your auto generated mapping file and its correspoding database tabel structure?


Top
 Profile  
 
 Post subject: Re: SQL Server identity not generated in the Mapping Files
PostPosted: Tue Jun 16, 2009 3:00 pm 
Newbie

Joined: Mon Jun 15, 2009 10:51 am
Posts: 4
Hello Please find my Users Table structure and the generated mapping file below.
I am giving you the create script for the Table

Users Table:
Code:
CREATE TABLE [dbo].[Users](
   [userid] [int] IDENTITY(1,1) NOT NULL,
   [firstname] [varchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
   [lastname] [varchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
   [password] [varchar](8) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
   [phone] [varchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
   [email] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
   [username] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
   [createUser] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
   [createDate] [datetime] NOT NULL,
   [updateUser] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
   [updateDate] [datetime] NULL,
CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED
(
   [userid] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]


Users.hbm.xml

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jun 6, 2009 7:40:18 PM by Hibernate Tools 3.2.4.GA -->
<hibernate-mapping>
    <class name="Users" table="Users" schema="dbo" catalog="suiteaccess">
        <id name="userid" type="int">
            <column name="userid" />
            <generator class="assigned" />
        </id>
        <property name="firstname" type="string">
            <column name="firstname" length="30" not-null="true" />
        </property>
        <property name="lastname" type="string">
            <column name="lastname" length="30" not-null="true" />
        </property>
        <property name="password" type="string">
            <column name="password" length="8" not-null="true" />
        </property>
        <property name="phone" type="string">
            <column name="phone" length="20" />
        </property>
        <property name="email" type="string">
            <column name="email" length="50" />
        </property>
        <property name="username" type="string">
            <column name="username" length="50" not-null="true" />
        </property>
        <property name="createUser" type="string">
            <column name="createUser" length="50" not-null="true" />
        </property>
        <property name="createDate" type="timestamp">
            <column name="createDate" length="23" not-null="true" />
        </property>
        <property name="updateUser" type="string">
            <column name="updateUser" length="50" />
        </property>
        <property name="updateDate" type="timestamp">
            <column name="updateDate" length="23" />
        </property>
    </class>
   
</hibernate-mapping>



Top
 Profile  
 
 Post subject: Re: SQL Server identity not generated in the Mapping Files
PostPosted: Fri Jun 19, 2009 10:34 am 
Regular
Regular

Joined: Wed Jun 20, 2007 1:53 am
Posts: 75
Hi,

You have defined userid as primary key, so that hibernate tool genrated mapping file with <id> as userid. I think by default its generator class set to 'assigned' .

Which generator class(assigned,increment,etc.,) would you expect to be mapped in generated mapping files?

which DB are you using?


Top
 Profile  
 
 Post subject: Re: SQL Server identity not generated in the Mapping Files
PostPosted: Mon Jun 22, 2009 12:02 pm 
Newbie

Joined: Mon Jun 15, 2009 10:51 am
Posts: 4
I am using SQL Server 2005. I want it to be identity
Is it possible?


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