Reputation: 65
Im working on a Spring (not Boot!) project, with Hibernate and PostgreSQL database. I also use Flyway for migration. I use Flyway to generate the schema of the database, and insert initial data to it with given SQL scripts in my resources folder. For this reason, I excluded the hibernate.hbm2ddl.auto property from my hibernate.properties file. On the startup, the schema is created and the data is inserted to the database, but my problem is, that this way Hibernate doesn't generate its sequence, and I cant save data from the application:
org.postgresql.util.PSQLException: ERROR: relation "hibernate_sequence" does not exist
What can I do with this?
Upvotes: 2
Views: 13511
Reputation: 846
As you didn't provide any code not sure what is wrong there, assume missing @SequenceGenerator annotation, I'll provide the one is working for me.
@Entity
@Table(name = "your_table")
@SequenceGenerator(name = "your_table_id_seq", sequenceName = "your_table_id_seq", allocationSize = 1)
public class YourTable implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "your_table_id_seq")
private Long id;
. . .
Upvotes: 6
Reputation: 191
You need to create a sequence like this:
CREATE SEQUENCE hibernate_sequence START 1;
Upvotes: 3