Question: JPA - How to set the value in additional column of the join table

Question

JPA - How to set the value in additional column of the join table

Answers 0
Added at 2016-12-01 11:12
Tags
Question

I have two entities

  1. Groups ,
  2. Users

DB tables

  1. groups,
  2. users
  3. groups_users (join table having four columns namely gid, uid , createdate, isdeleted)

Questions

  1. When I save the group entity, the createdate should also be set in the DB.
  2. When I delete the group entity the isdeleted should be set to true in the DB.

Is there any way in JPA to achive this?

here is the relation I have created in entity classes.

Entity : Group

@ManyToMany(cascade=CascadeType.ALL)
    @JoinTable(
            name="group_agent", 
            joinColumns=@JoinColumn(name="group_id", referencedColumnName="group_gid"), 
            inverseJoinColumns=@JoinColumn(name="userid", referencedColumnName="userid"))
private Set<User> users;

Entity : Users

@ManyToMany(mappedBy="users", fetch=FetchType.EAGER)
private List<Group> groups;

Thanks.

Answers to

JPA - How to set the value in additional column of the join table

Source Show
◀ Wstecz