Announcement Announcement Module
No announcement yet.
spring-data-jpa primary key handling Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • spring-data-jpa primary key handling

    Hi guys,

    I'm new to spring and I'm trying to figure out if I'm doing something wrong or this is the way that spring-data-jpa behaves.

    Let's say that I have an entity Customer where the primary key is called cid and it's an int. Also it is not auto_inc.

    Therefore in my class I have something like that

    private int customerId;
    Also, I have a repository that extends CrudRepository.
    Now, let's say that I have already 3 customers with ids 1, 2, 3.

    The strange this is that if I create a new customer and give him id=3, then I get no exception and the existing customer with id=3 is overwritten by the new one!
    Also, if I edit customer with id=2 and change his id to 1, then again customer with id=1 is overwritten by the update of customer with id=2!!.

    Thank you in advance