How to annotate id so it's autoincrements without SEQUENCE table?

16,420

Solution 1

You could define myId as auto increment / identity column in database and annotate corresponding field entity following way:

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long myId;

That works at least with H2 1.3.160 & Hibernate 3.6.8.

Solution 2

Did you try this..

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;
Share:
16,420
bunnyjesse112
Author by

bunnyjesse112

i hate my life

Updated on June 09, 2022

Comments

  • bunnyjesse112
    bunnyjesse112 almost 2 years

    I have a trouble generating id's for new entities, i tried:

    @Id
    @GeneratedValue
    private Long myId;
    

    and

    @Id
    @GeneratedValue(generator="increment")
    @GenericGenerator(name="increment", strategy = "increment")
    private Long myId;
    

    but on entityManager.persist i get Table "SEQUENCE" not found In pure hibernate generator class="increment" worked for me just fine.