views:

442

answers:

2

I have the following code:

@Entity
@Table(name = "my_table", schema = "my_schema")
@SequenceGenerator(name = "my_table_id_seq", sequenceName = "my_table_id_seq", 
                   schema = "my_schema")
public class MyClass {
    @Id
    @GeneratedValue(generator = "my_table_id_seq", 
                    strategy = GenerationType.SEQUENCE)
    private int id;

}

Database: Postgresql 8.4, Hibernate annotations 3.5.0-Final.

When saving the object of MyClass it generates the following SQL query:

select nextval('my_table_id_seq')

So there is no schema prefix and therefore the sequence cannot be found. When I write the sequenceName like

sequenceName = "my_schema.my_table_id_seq"

everything works.

Do I have misunderstandings for meaning of schema parameter or is it a bug? Any ideas how to make schema parameter working?

A: 

Hmmm, I don't work with the internals of hibernate much but there is some info here:

https://forum.hibernate.org/viewtopic.php?p=2406761

You can also set the default schema for a user connecting to PostgreSQL via ALTER USER ... SET SEARCH_PATH

Joshua D. Drake
A: 

This sounds like a bug: the JPA provider should honor the "new" (since Java Persistence 2.0) schema and catalog attributes of the @SequenceGenerator annotation. I suggest to raise a Jira issue (the annotations and entity manager projects are now under core), couldn't find any existing one.

Pascal Thivent