I've verified that the object I'm trying to update has a specific ID value for the entry I'm trying to replace, and that the object that gets returned is a new entry with a later ID value. I thought so long as you provided an ID value, it would update, not make a new one. Are there some caveats that I'm missing?
System.out.println("!Parsed article ID = " + article.getID());
Article returnedArticle = articleRepo.save(article);
System.out.println("Saved article ID = " + returnedArticle.getID());
outputs:
!Parsed article ID = 1
Saved article ID = 37
Object Def:
@Entity
abstract class DatabaseObject {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
...and other fields in the extending article entity
=== Update 2/22 17:00EST ===================================
I'm using MySQL, and the query(s) generated through Hibernate is:
Hibernate:
select
article0_.id as id2_0_0_,
article0_.approved as approved3_0_0_,
article0_.creators as creators4_0_0_,
article0_.publish_date as publish_5_0_0_,
article0_.title as title6_0_0_,
article0_.text as text7_0_0_
from
database_object article0_
where
article0_.id=?
and article0_.dtype='Article'
Hibernate:
select
next_val as id_val
from
hibernate_sequence for update
Hibernate:
update
hibernate_sequence
set
next_val= ?
where
next_val=?
Hibernate:
insert
into
database_object
(approved, creators, publish_date, title, text, dtype, id)
values
(?, ?, ?, ?, ?, 'Article', ?)