Hi,
I'm using Hibernate Tools 4.0.0-CR1 and Hibernate 4.2 (including Hibernate Validator) via the following build.xml target to generate my DDL:
Code:
<target name="schemaexport" depends="jar" description="Exports a generated schema to DB and files">
<path id="lib.path">
<fileset refid="lib" />
<pathelement location="${jboss.home}/modules/org/apache/xerces/main/xercesImpl-2.9.1-jbossas-1.jar"/>
<pathelement location="${jar.dir}" />
</path>
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="lib.path"/>
<hibernatetool destdir="${basedir}">
<classpath refid="lib.path"/>
<jpaconfiguration persistenceunit="TIC" propertyfile="hibernate-console.properties" />
<hbm2ddl outputfilename="${dist.dir}/db_ddl.sql" format="true"/>
</hibernatetool>
<concat destfile="${dist.dir}/tic.sql" fixlastline="yes">
<filelist dir="${dist.dir}" files="db_ddl.sql" />
<filelist dir="${jar.dir}" files="import.sql" />
</concat>
</target>
My hibernate-console.properties is as follows:
Code:
hibernate.connection.password=tic
hibernate.connection.username=tic
hibernate.connection.driver_class=org.postgresql.Driver
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.connection.url=jdbc:postgresql://127.0.0.1:5432/db
hibernate.connection.provider_class=org.hibernate.connection.DriverManagerConnectionProvider
hibernate.datasource=
hibernate.transaction.manager_lookup_class=
I double-checked that the jars are in my lib.path...
A sample entity looks like this:
Code:
@Entity
public class Title implements Serializable {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Size(max = 50) @NotEmpty @Column(length = 50)
private String titlename;
/** User visible short version of the title. */
@Size(max = 50)
private String short;
}
The problem here is that hbm2ddl generates a proper "varchar(50)" for "titlename" but a generic "varchar(255)" for "short". I encountered similar problems with @NotNull and basically every other bean validation annotation. According to http://docs.jboss.org/hibernate/validator/4.2/reference/en-US/html_single/#validator-checkconstraints-db this should just work[tm]. What am I doing wrong?