1

I'm trying to map a class with Hibernate annotations but it tells me that hibernate_sequence doesn't exist.

I use mysql.

@Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column()
    private int id;

this is ho I've declared the auto_increment field. What I'm missing?

Stefano Pisano
  • 440
  • 1
  • 8
  • 24
  • I think you are asking the same question http://stackoverflow.com/questions/32968527/hibernate-sequence-doesnt-exist – Storms786 Sep 30 '16 at 14:36

3 Answers3

1

change the @GeneratedValue(strategy = GenerationType.IDENTITY) to

@GeneratedValue(strategy = GenerationType.AUTO)

try it, It worked for me and Once the table is create, change the GenerationType back to IDENTITY, TABLE, or other generationTypes.

Tadele Ayelegn
  • 4,126
  • 1
  • 35
  • 30
0

In your persistence.xml, try adding this

<property name="hbm2ddl.auto" value="update"/>

This might possibly work.

AppSensei
  • 8,270
  • 22
  • 71
  • 99
  • It's not the solution and could be dangerous on production environment, because the hibernate will be able to change the database structure. – Renan Ceratto Feb 28 '19 at 14:29
0

You may manually create the sequence in db

create sequence hibernate_sequence start with 1 increment by 1

But again not all db support sequence

For example if you are working with Mysql then above query will fail. In mysql you need to use AUTO_INCREMENT with primary key as in below query

CREATE TABLE `mysql_table` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `name` varchar(500) DEFAULT NULL,
  PRIMARY KEY (`id`),
);
abhinav kumar
  • 1,487
  • 1
  • 12
  • 20