Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PUT creates new records for @OneToOne association [DATAREST-1428] #1789

Open
spring-projects-issues opened this issue Sep 25, 2019 · 0 comments
Open
Assignees
Labels

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Sep 25, 2019

Carlos Guzman opened DATAREST-1428 and commented

Let's say these are the entities and repository configurations:

@Entity
class Customer {
 @Id @GeneratedValue
 Long id;
 String name;
 @OneToOne(cascade = CascadeType.ALL)
 Info info;
}
@Entity
class Info {
 @Id @GeneratedValue
 Long id;
 String theInfo;
}
@RepositoryRestResource
interface CustomerRepository extends CrudRepository<Customer, Long> {
}

Nothing complex here. *Info* entity needs to be embedded in Costumer and persisted together. Only *Costumer* repository is exposed/created.

After creating a *Costumer* with POST, the records are stored as expected:

{
   "name": "John",
   "info": {
      "theInfo": "the info here"
   }
}

Customer table:

ID NAME INFO_ID
1 John 2

Info table:

ID THE_INFO
2 the info here

 

But when an update is made to *Costumer*, a new record is created for *Info* and the new ID assigned to *Costumer*:

{
   "name": "John Doe",
   "info": {
      "theInfo": "updated info"
   }
}

Customer table:

ID NAME INFO_ID
1 John Doe 3

Info table:

ID THE_INFO
2 the info here
3 updated info

Which is incorrect. A duplicated record is created in the *Info* table.
I'm expecting the same *Info* record and only the data being updated.
Something like this:

Customer table:

ID NAME INFO_ID
1 John Doe 2

Info table:

ID THE_INFO
2 updated info

The sample project is in https://github.com/cguZZman/put-issue-spring-data-rest.git

Also, I have the fix ready if the bug is confirmed


Affects: 3.1.10 (Lovelace SR10)

Reference URL: https://github.com/cguZZman/put-issue-spring-data-rest.git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants