Announcement Announcement Module
Collapse
No announcement yet.
How to update association on a One-to-many relationship to an Embeddable object Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to update association on a One-to-many relationship to an Embeddable object

    Hi,

    I have a very simple data model with two tables:
    • T_SYSTEM having columns SYSTEM_ID (the pk), NAME
    • T_SYSTEM_DEPENDENCY having columns SYSTEM_ID and TARGET_SYSTEM_ID : both are FKs to the T_SYSTEM table
    The corresponding model in Java is:

    Code:
    @Entity(name="T_SYSTEM")
    
    public class System {
    
    
    
        @Id @GeneratedValue
    
        @Column(name="SYSTEM_ID")
    
        private Long id;
    
        
    
        @Column(unique=true,nullable=false)
    
        private String name;
    
    
        @ElementCollection
    
        @CollectionTable(
    
                name="T_SYSTEM_DEPENDENCY",
    
                [email protected](name="SYSTEM_ID",nullable=false))
    
        private List<SystemDependency> dependencies;
    
    //...
    }
    The embeddable class is:
    Code:
    @Embeddable
    
    public class SystemDependency {
    
        
    
        @OneToOne(cascade=CascadeType.PERSIST)
    
        @JoinColumn(name="TARGET_SYSTEM_ID", nullable=false)
    
        private System target;
    
    
    
        @Column
    
        private String description;
    
    // ...
    }
    The JPA repository is implemented by Spring data JPA and all sort of operations (CRUD and updating the dependencies of a given system) work perfectly well:

    Code:
    public interface SystemDAO extends CrudRepository<System, Long> {
    
    }
    Now comes the question ...

    Using Spring Data Rest, I get a JSON API to create a new entity, read and delete. Regarding the update, updating the name property works fine but I did not manage so far to update the dependencies property : a one-to-many relationship to an Embeddable object.

    Should it be done as an update on the /systems/<id> resource?

    What would be the message to pass to for instance update system ABC (resource /systems/176) to tell that it depends on DEF (resource /systems/177)?

    For example the JSON representation for ABC is:

    Code:
    {
      "name" : "ABC",
      "dependencies" : [ ],
      "_links" : {
        "self" : {
          "href" : "http://root_url/systems/176"
        }
      }
    }
    Last edited by adelinor; Apr 24th, 2014, 02:57 AM.
Working...
X