Hibernate version: Hibernate 3.0 rc1
In hibernate 2.x when using the id generator "native" with this configuration:
<id name="id" column="id" type="java.lang.Long" unsaved-value="null">
<generator class="native">
<param name="sequence">seq_foo_name</param>
</generator>
</id>
The old schema export tool generates a sequence named "seq_foo_name" in the DDL script.
Now with the annotations I can't find the way to specify the sequence name.
the way I run the SchemaExport:
Code:
public static void main(String[] args) {
Configuration cfg = new AnnotationConfiguration()
.addAnnotatedClass(Patient.class)
.addAnnotatedClass(Gender.class);
Properties props = new Properties();
props.setProperty(Environment.USER, "test");
props.setProperty(Environment.PASS, "*****");
props.setProperty(Environment.DIALECT, PostgreSQLDialect.class.getName());
props.setProperty(Environment.URL, "jdbc:postgresql://server/dbTest");
props.setProperty(Environment.DRIVER, Driver.class.getName());
props.setProperty(Environment.SHOW_SQL, "true");
SchemaExport schemaExport = new SchemaExport(cfg, props);
schemaExport.setOutputFile("c:/ddl.txt");
schemaExport.create(false, true);
}
this are the examples I've tried:example 1:
Code in Patient Class:
Code:
@Id(generate=GeneratorType.AUTO)
@SequenceGenerator(name="gen_name", sequenceName="seq_foo_name")
public Long getId() {
return id;
}
this doesn't produce errors but in the DDL generates the following line:
create sequence hibernate_sequence
example 2:
Code in Patient Class:
Code:
@Id(generate=GeneratorType.AUTO, generator="gen_name")
@SequenceGenerator(name="gen_name", sequenceName="seq_foo_name")
public Long getId() {
return id;
}
this produces the following error:
16/03/2005 18:03:45 org.hibernate.cfg.AnnotationConfiguration addAnnotatedClass
FATAL: Could not compile the mapping annotations
org.hibernate.AnnotationException: Incompatible generator between Id.generate and its named generator: native!=gen_name
at org.hibernate.cfg.AnnotationBinder.bindId(AnnotationBinder.java:957)