Hibernate schema parameter doesn't work in @SequenceGenerator annotation Hibernate schema parameter doesn't work in @SequenceGenerator annotation postgresql postgresql

Hibernate schema parameter doesn't work in @SequenceGenerator annotation


Same problem here, looks like a bug to me. I´m using hibernate 3.6.7Looking at the source code i see a method org.hibernate.cfg.annotations.reflection.JPAOverridenAnnotationReader#buildSequenceGeneratorAnnotation(Element element) that seems to copy the values of name, sequence-name, initial-value and allocation-sizeattributes, but I see no reference to catalogor schema

i expected to see something analogous to method getTable(Element tree, XMLContext.Default defaults) (of the same class) which has

annotation.setValue("schema", table.schema());annotation.setValue("catalog", table.catalog());` 

or buildTableGeneratorAnnotation which has

copyStringAttribute(ad, element, "catalog", false);copyStringAttribute(ad, element, "schema", false);

So, even if a little hackish, the way around -for this version at least- seems to be prefixing the sequenceName as you say.


My workaround looks like this (JPA 2.1, Hibernate 4.3.8.Final, PostgreSQL 9.4):

@SequenceGenerator(name = "seq_name", sequenceName = "my_schema.seq_name", schema = "my_schema", allocationSize = 1, initialValue = 1)


I solved this problem in postgresql 9.6 by only adding my schema before the sequence name, like this:

(before) sequence name: seq_area_tematica(after) sequence name: sisbp.seq_area_tematica

And its works. See the code:

@Id@Column(name="seq_area_tematica")@GeneratedValue(generator="sequence",strategy=GenerationType.SEQUENCE) @SequenceGenerator(name="sequence",sequenceName="sisbp.seq_area_tematica")private Long id;

See the "sisbp" before the sequenceName. The sequenceName was "seq_area_tematica" and now is "sisbp" (schema) + "seq_area_tematica".