Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Hibernate: Creating Entities versus the database schema, best way create the Sequence

 
Ranch Hand
Posts: 34
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I try to make myself 'comfortable' with the Java eco-system as JPA and Hibernate.

I have for instance made a class employee with sequence:


I can CRUD records with Postman is working perfectly.

But now I have inserted records with SQL (INSERT INTO table name ()).
Now I try to insert a record with postman, I get the error message: rg.h2.jdbc.JdbcSQLIntegrityConstraintViolationException: Unique index or primary key violation: "PRIMARY KEY ON PUBLIC.ADDRESS(ID) [1, 'town name', '0', 'street name']"; SQL statement:

I think that's due that I add records by SQL statements. Hibernate 'thinks'  the sequence is still one and I can imagine that it goes wrong.

In the 'real (=production)' environment, what is than the best way to implement this?
Defining the complete schema with Liquibase/flyaway for example and simply define sequence as:

And are there some more 'little' things where I need to have tobe where off?
 
I am a man of mystery. Mostly because of this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic