Auto-incremented primary key

Using hibernate 5.4, postgres 10 with IntelIiJ Ultimate, impossible to get auto-incremented primary key
With this following code, the sequence “warehouses_id_seq” is created but the primary key is not incremented

@Entity
@Table(name = "warehouses")
@SequenceGenerator(name = "SEQUENCE_WAREHOUSE", sequenceName = "warehouses_id_seq", allocationSize = 1)
public class Warehouse implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQUENCE_WAREHOUSE")
    @Column(name = "id")
    private Integer id;

What mean don’t increment?
In config set show_sql , and run application : do u see this " call next value for …"?
Maybe u don’t have transaction … in postgres go to schem and run nextval
maybe u wrap u code into try catch and don’t see this “No EntityManager with actual transaction available for current thread”

no, I don’t see " call next value for …"?

I think we should get
< alter table warehouses alter column id set default nextval(‘public.warehouses_id_seq’); >
in the sql log.

I have to insert this manualy after application has been run

No
create sequence warehouses_id_seq start with 1 increment by 1
Then hibernate do: next val
and set into id in u Object(Entity) then save object

Thank’s for your reply,

but I would like Hibernate does it automaticaly by running the appli !!

how do you create sequence warehouses_id_seq start with 1 increment by 1 with java?

I try with initialValue = 1

if you want do this:
U need delete generate sequence , than use migaration application like “flyway”
write code like this:

create table test(
id bigserial
)

in java

@Entity
class Test {

@Id
Long id;

}

In java its call - ddl create auto

Thanks!
That means I need to use an additional migration tool to achieve this! I’m a little bit desapointed

yes, it’s best idea, but if u work for example in h2 , use ddl.auto -

create-drop

my configuration is

update

“update” as I’m working on an existing data base.
Maybe it would work with “create-drop”

Try use validate schema , maybe u configuration doest’t work

even with ‘create-drop’ it doesn’t work

I give up !

Do u use spring? Spring boot? Or only hibernate?

No, I use only Hibernate

ok, i have more information about u code :wink:
what configuration file do u use ?
hibernate.cfm.xml or perstence.xml?
can u debug u code? AdapterJpaVender can u debug to see properties when SessionFactory is up

Sorry for the delay I was out of my office.
I use hibernate.cfm.xml
I will debug code

I don’t use AdapterJpa Vendor as I don’t use Spring.
I use Dialect instead in hibernate.cfm.xml :

    <property name="hibernate.dialect">
        org.hibernate.dialect.PostgreSQL10Dialect
    </property>

http://jpwh.org/examples/jpwh2/jpwh-2e-examples-20151103.zip
in this code u will see how work with hibernate.cfg ( but u need understand ) how work maven

I should get “alter table warehouses alter column id set default nextval(‘public.warehouses_id_seq’);”
into the sequence. But finaly the id column of the database has not get any default value.
Is there any hibernate expert able ti explain me why?
Thanks

In hibernete i don’t see default nextval…