-->
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: Cannot create unique column using SchemaExport
PostPosted: Sun Nov 14, 2004 10:42 pm 
Newbie

Joined: Sat Sep 18, 2004 8:58 am
Posts: 4
I want to create a unique column "dtString" I have specified the unique="true" constraint in the hbm file but the generated ddl doesn't contain the unique constraint. What am I doing wrong?


Hibernate version:
version 2.1.4, 02. June 2004

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping package="com.nokia.sspa.vobjects">
<class name="VObjectOthertypes" table="sspa_othertypes">

<id name="id" column="id" type="string">
<generator class="uuid.hex"/>
</id>

<property name="lastModified" unique="false" not-null="false" column="lastModified" />
<property name="modifierId" unique="false" not-null="false" column="modifierId" />
<property name="otherId" unique="false" not-null="true" type="string">
<column name="otherId" length="128"/>
</property>
<property name="dtShort" unique="false" not-null="true" column="dtShort" />
<property name="dtLong" unique="false" not-null="true" column="dtLong" />
<property name="dtInteger" unique="false" not-null="true" column="dtInteger" />
<property name="dtString" unique="true" not-null="true" type="string">
<column name="dtString" length="128"/>
</property>
<property name="dtBoolean" unique="false" not-null="true" column="dtBoolean" />
</class>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:
postgres (PostgreSQL) 8.0.0beta4

The generated SQL (show_sql=true):
[schemaexport] create table sspa_othertypes (
[schemaexport] id VARCHAR(255) not null,
[schemaexport] lastModified TIMESTAMP,
[schemaexport] modifierId VARCHAR(255),
[schemaexport] otherId VARCHAR(128),
[schemaexport] dtShort INT2 not null,
[schemaexport] dtLong INT8 not null,
[schemaexport] dtInteger INT4 not null,
[schemaexport] dtString VARCHAR(128),
[schemaexport] dtBoolean BOOL not null,
[schemaexport] primary key (id)
[schemaexport] );

Debug level Hibernate log excerpt:

_________________
Mousa


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 22, 2005 7:40 am 
Newbie

Joined: Tue Feb 22, 2005 7:33 am
Posts: 3
This is an old post, but as I spent hours searching, here's the solution just for the sake of completeness:

<property name="dtString" unique="true" not-null="true" type="string">
<column name="dtString" length="128"/>
</property>

if you specify an inner column tag and do not use the shorter form, the unique and not-null attributes have to be moved to the column tag:

<property name="dtString" type="string">
<column name="dtString" length="128" unique="true" not-null="true" />
</property>

SchemaExport does not warn you in the first case and simply does not create the constraint, at least up to Hibernate Tools 2.1.3

_________________
Jonas Kilian


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.