-->
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: SchemaExport ignores column length
PostPosted: Fri Jun 24, 2005 6:05 pm 
Newbie

Joined: Tue Jun 21, 2005 9:47 pm
Posts: 1
Location: Caracas, Venezuela
Hi,

I'm found that SchemaExport tool generates columns definitions without the length attribute specified on the hbm files, both on SQL Server and MySQL. Instead, hibernate creates the columns with the default length according to the datatype, for example, 255 for VARCHAR. Because MySQL doesn't allows primary keys longer than 500 characters, having a table with two or more varchar columns as the PK doesn't work, even when the columns legth specified on the hbm files are less than 500 characters.

Hibernate version: 3.0

Mapping documents:
Code:
<hibernate-mapping package="ve.usb.jgm.repo.backend.hibernate">

        <class  name="HbLibrary"
                table="jdm_library">
               
                <!--
                <id name="id">
                    <generator class="native"/>
                </id>
                -->
               
                <id name="name">
                    <generator class="assigned"/>
                </id>   
               
                <property   name="name"
                            type="string"
                            not-null="true"
                            unique="true"
                            update="false" insert="false">
                    <column name="name" length="50" sql-type="char(50)"/>
                </property>

                <property   name="description"
                            type="string"
                            not-null="true"/>

                <set name="allowedRoles"
                     table="jdm_library_allowedroles">
                    <key>
                        <column name="library_name" length="50"/>
                    </key>
                    <element type="string" column="roleName"/>
                </set>

                <set name="versions" inverse="true"  cascade="all,delete-orphan">
                    <key>
                        <column name="library_name" length="50" sql-type="char(50)"/>
                    </key>
                    <one-to-many class="HbVersion"/>
                </set>
        </class>
</hibernate-mapping>

<hibernate-mapping package="ve.usb.jgm.repo.backend.hibernate">

        <class  name="HbVersion"
                table="jdm_version">
               
                <!--<id name="id">
                    <generator class="native"/>
                </id>-->
               
                <composite-id name="id" class="HbVersionId">
                    <key-property name="library_name"/>
                    <key-property name="major"/>
                    <key-property name="minor"/>
                </composite-id>
               
                <many-to-one name="library" update="false" insert="false">
                    <column name="library_name" not-null="true" length="50" sql-type="char(50)"/>
                </many-to-one>

                <property   name="major"
                            type="int"
                            not-null="true"
                            update="false" insert="false"/>

                <property   name="minor"
                            type="int"
                            not-null="true"
                            update="false" insert="false"/>
               
                <property   name="description"
                            type="string"
                            not-null="true"/>

                <property   name="stubsJar"
                            type="binary"
                            not-null="true">
                    <column name="stubsJar" length="5242880"/>
                </property>
                           
                <property   name="javadocZip"
                            type="binary"
                            not-null="true">
                    <column name="javadocZip" length="5242880"/>
                </property>

                <set name="allowedRoles"
                     table="jdm_version_allowedroles">
                    <key>
                        <column name="library_name" length="50" sql-type="char(50)"/>
                        <column name="version_major"/>
                        <column name="version_minor"/>
                    </key>
                    <element type="string" column="roleName"/>
                </set>
               
                <set name="revisions" inverse="true" cascade="all,delete-orphan">
                    <key>
                        <column name="library_name" length="50" sql-type="char(50)"/>
                        <column name="version_major"/>
                        <column name="version_minor"/>
                    </key>
                    <one-to-many class="HbRevision"/>
                </set>

        </class>
</hibernate-mapping>

<hibernate-mapping package="ve.usb.jgm.repo.backend.hibernate">

        <class  name="HbRevision"
                table="jdm_revision">
               
                <!--<id name="id">
                    <generator class="native"/>
                </id>-->
               
                <composite-id class="HbRevisionId">
                    <key-property name="library_name"/>
                    <key-property name="version_major"/>
                    <key-property name="version_minor"/>
                    <key-property name="number"/>
                </composite-id>
               
                <many-to-one name="version" not-null="true" update="false" insert="false">
                    <column name="library_name" length="50" sql-type="char(50)"/>
                    <column name="version_major"/>
                    <column name="version_minor"/>
                </many-to-one>

                <property   name="number"
                            type="int"
                            not-null="true"
                            update="false" insert="false"/>
               
                <set name="bytecode" inverse="true" cascade="all,delete-orphan">
                    <key>
                        <column name="library_name" length="50" sql-type="char(50)"/>
                        <column name="version_major"/>
                        <column name="version_minor"/>
                        <column name="revision_number"/>
                    </key>
                    <one-to-many class="HbBytecode"/>
                </set>

        </class>
</hibernate-mapping>

<hibernate-mapping package="ve.usb.jgm.repo.backend.hibernate">

        <class  name="HbBytecode"
                table="jdm_bytecode">
               
                <!--<id name="id">
                    <generator class="native"/>
                </id>-->

                <composite-id name="id" class="HbBytecodeId">
                    <key-property name="library_name"/>
                    <key-property name="version_major"/>
                    <key-property name="version_minor"/>
                    <key-property name="revision_number"/>
                    <key-property name="className"/>
                </composite-id>               

                <many-to-one name="revision" not-null="true" update="false" insert="false">
                    <column name="library_name" length="50" sql-type="char(50)"/>
                    <column name="version_major"/>
                    <column name="version_minor"/>
                    <column name="revision_number"/>
                </many-to-one>

                <property   name="className"
                            type="string"
                            not-null="true"
                            update="false" insert="false">
                    <column name="className" length="100" sql-type="char(100)"/>
                </property>
                   
                           
                <property   name="classData"
                            type="binary"
                            not-null="true">
                    <column name="classData" length="524288"/>
                </property>
        </class>
</hibernate-mapping>

Name and version of the database you are using: MSSQLServer 2000 with jTDS JDBC Driver and MySQL 3.23.58 with InnoDB

The generated SQL (show_sql=true): (Only for MSSQLServer2000)
Code:
5133   DEBUG: create table jdm_bytecode (
   library_name varchar(255) not null,
   version_major int not null,
   version_minor int not null,
   revision_number int not null,
   className varchar(255) not null,
   classData image null,
   primary key (library_name, version_major, version_minor, revision_number, className)
)
5137   DEBUG: create table jdm_library (
   name varchar(255) not null,
   description varchar(255) not null,
   primary key (name)
)

5143   DEBUG: create table jdm_revision (
   library_name varchar(255) not null,
   version_major int not null,
   version_minor int not null,
   number int not null,
   primary key (library_name, version_major, version_minor, number)
)

5151   DEBUG: create table jdm_version (
   library_name varchar(255) not null,
   major int not null,
   minor int not null,
   description varchar(255) not null,
   stubsJar image null,
   javadocZip image null,
   primary key (library_name, major, minor)
)
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 27, 2005 3:29 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
i think if you set the length on the *defining* column then it should work.

In this one the <key-property> is the *defining* column and it does not have a column length specified.

_________________
Max
Don't forget to rate


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.