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]