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

PATCH for non-resource associations doesn't work as expected [DATAREST-931] #1294

Closed
spring-projects-issues opened this issue Nov 2, 2016 · 3 comments
Assignees
Labels

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Nov 2, 2016

Destan Sarpkaya opened DATAREST-931 and commented

User has a repository and Phone has not. [id and some other fields are pruned in below examples for brevity, see full entities in example code]

@Entity
public class User {

        private String name;

	@Column(nullable = false)
	@Temporal(value = TemporalType.TIMESTAMP)
	private Calendar creationDate;

	@OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
	private List<Phone> phones;
}

@Entity
public class Phone extends BaseEntity {

	@Column(nullable = false)
	@Temporal(value = TemporalType.TIMESTAMP)
	private Calendar creationDate;

	@ManyToOne(fetch = FetchType.EAGER)
	private User user;
}

In this case patch for /users/1 with following data works:

{
   "name":"John Doe X",
   "phones":[
      {
         "id":1,
         "creationDate":"2016-11-02T07:34:02.806+0000",
         "label":"work",
         "number":"00000000"
      }
   ]
}

but following data fails with not-null-constraint error for creationDate:

{
   "name":"John Doe X",
   "phones":[
      {
         "id":1,
         "label":"work",
         "number":"00000000"
      }
   ]
}

PATCH works selectively on resources however doesn't work as expected for inline data which is not a resource (in this case "phone")


Affects: 2.5.4 (Hopper SR4)

Attachments:

Backported to: 2.5.5 (Hopper SR5), 2.4.7 (Gosling SR7)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 2, 2016

Oliver Drotbohm commented

Thanks for filing this. As you've already spent the time to create a sample project, any chance you add a test case that shows the erroneous behavior?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 2, 2016

Oliver Drotbohm commented

Nevermind, I got it. Looks like we need to apply some of our massaging to collections, too. Generally speaking, using a proper media type like JSON Patch will prevent problems like this as you can be much more specific about what your intentions are as a client

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 3, 2016

Oliver Drotbohm commented

That should be fixed with the solution explained above. We now inspect arrays, too

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