-->
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: Q: is type 'integer' ok for id with generator 'identity' ?
PostPosted: Thu Jan 29, 2004 8:09 am 
Newbie

Joined: Fri Jan 09, 2004 10:24 am
Posts: 7
Can I use the type 'integer' for an id that has generator 'identity' ?

I ask because the SQL to create the table created by SchemaExport is wrong for Sybase.

If I have the mapping file:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="test.ABusinessObject" table="ABusinessObject">
<id name="id" type="integer" unsaved-value="null">
<generator class="identity"/>
</id>
</class>
</hibernate-mapping>

then SchemaExport produces SQL:
create table ABusinessObject (id INT IDENTITY NOT NULL, primary key (id))
But this fails on Sybase ('Identity field 'id' must be a numeric with a scale of 0 and not null allowed')

If I change the type to long i.e.
<id name="id" type="long" unsaved-value="null">
the SQL is okay
create table ABusinessObject (id NUMERIC(19,0) IDENTITY NOT NULL, primary key (id))

my dialect property is set to
<property name="dialect">net.sf.hibernate.dialect.SybaseDialect</property>

is there a workaround I can use or do I have to have 'long' id's ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 29, 2004 7:27 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
try the sql-type attribute

_________________
Emmanuel


Top
 Profile  
 
 Post subject: success!
PostPosted: Fri Jan 30, 2004 6:05 am 
Newbie

Joined: Fri Jan 09, 2004 10:24 am
Posts: 7
thanks!

I changed my mapping to
Code:
<class name="test.ABusinessObject" table="ABusinessObject">
   <id name="id" type="integer" unsaved-value="null">
      <column name="id" sql-type="numeric(10,0)"/>
      <generator class="identity"/>
   </id>
      <property name="aproperty" type="integer"/>
</class>

this allowed SchemaExport to produce
Code:
create table ABusinessObject (id numeric(10,0) IDENTITY NOT NULL, aproperty INT null, primary key (id))


So this gives me a mapping that I can also use to generate DDL for creating the table in Sybase.

But ...
It seems to me that this should be handled in the hibernate SybaseDialect.

Currently sqlCreateString method of net.sf.hibernate.mapping.Table gets the SQL for creating a column in two steps
1. ask the Dialect for the type to use for that column
2. if the column is flagged as an identity column ask the Dialect for the qualifier to apply (getIdentityColumnString() of Dialect)

from my perspective it looks like this should be changed to test if the column is flagged as an identiy column ask the Dialect for identity type && the identity column string
else
proceed as normal (i.e. existing code)

should l I raise this in the hibernate JIRA ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 30, 2004 1:32 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
yes please. With patch if you have time.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: HB-684 raised
PostPosted: Tue Feb 03, 2004 2:03 pm 
Newbie

Joined: Fri Jan 09, 2004 10:24 am
Posts: 7
Hi,
I have posted an effort at a patch to fix this
http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?key=HB-684


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.