3

In a spring-boot webapp, i look for the update of only the @ElementCollection of an entity using JpaRepository given the member entity

public class Member implements Serializable {
    private static final long serialVersionUID = 1L;

    ...

    @ElementCollection
    @CollectionTable(name = "address", joinColumns = @JoinColumn(name = "member"))
    @OrderColumn(name = "idOrder")
    private List<Address> addresses;
...

Member repository

@Repository
public interface MemberRepository extends JpaRepository<Member, Long> {
...
}

of course the method save(member) can works but i aim to persist only the elementCollection and not to carry with other attributes of member entity

alveomaster
  • 1,681
  • 2
  • 12
  • 21
  • is there any specific reason you wanna do that? this seams pretty out of the idea of an entity in a jpa context – dom May 29 '18 at 14:00
  • In the business method i allow to the role1_user to edit and update only addresses from a dedicate form apply the form should modify only the CollectionElement nothing else so i look to implement this logic by avoiding the use of save(entity) method – alveomaster May 29 '18 at 14:15
  • If you just update the ElementCollection you should get the update behavior as described here: https://stackoverflow.com/questions/38893831/spring-data-crudrepositorys-save-method-and-update – Tuhin Kanti Sharma May 30 '18 at 06:06
  • Yes it is pretty clear that the save will update the whole entity attributes but i look for updating element collection only, may some one can help using @Query annotation – alveomaster May 30 '18 at 13:03
  • @alveomaster were you able to resolve this using @query? – sumit singh Nov 14 '18 at 15:14
  • @sumitsingh, follow these examples [link 1](https://thoughts-on-java.org/hibernate-tips-query-elementcollection/), [link 2](http://mydeveloperdiary.blogspot.com/2017/09/using-elementcollection-in-spring-jpa.html) in case of SELECT statements, for Update/Insert i still using the save(entity) method – alveomaster Nov 17 '18 at 12:59
  • Thanks! I was actually looking to use @Query for update as well, but had to resort to the save method at the end – sumit singh Nov 19 '18 at 11:07

0 Answers0