Dlaczego Hibernate Tools generowanie hbm2ddl nie uwzględnia adnotacji sprawdzania poprawności Bean?
Podsumowanie: Używam Hibernate Tools 4.0.0-CR1 i Hibernate 4.2 (w tym Hibernate Validator), ale sprawdzanie poprawności Bean nie jest pobierane. Schematjest prawidłowo wygenerowany podczas wdrażaniahibernate.hbm2ddl.auto=create-drop
.
Ale wolę generować mój DDL poprzez następujący cel build.xml:
<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>
Moje hibernate-console.properties jest następujące:
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=
Sprawdziłem dwukrotnie, czy słoiki są w mojej bibliotece lib.path ...
Przykładowy obiekt wygląda tak:
@Entity
public class Title implements Serializable {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Size(max = 50) @NotEmpty @Column(length = 50)
private String titlename;
@Size(max = 50)
private String shortTitle;
}
Problem polega na tym, że hbm2ddl generuje odpowiedni „varchar (50)” dla „titlename”, ale ogólny „varchar (255)” dla „shortTitle”. Napotkałem podobne problemy z @NotNull i zasadniczo każdą inną adnotacją sprawdzania poprawności bean. Wedługinstrukcja to powinno działać [tm]. Co ja robię źle?