I want to know how to create the table role_permission with the annotation @ManyToMany taking into account the attribute created_at in the table role_permission.
I know that I can do something like this:
public class Role implements Serializable{
@Id
@Column(name = "_id")
private String id;
@Column(name = "name")
@NotNull
private String name;
@Column(name = "description")
private String description;
@ManyToMany(cascade = {CascadeType.ALL})
@JoinTable(name="role_permission", schema=joinColumns={@JoinColumn(name="idRole")}, inverseJoinColumns={@JoinColumn(name="idPermission")})
private Set<Permission> permissions=new HashSet();
And
public class Permission implements Serializable{
@Id
@Column(name = "_id")
private String id;
@Column(name = "name")
@NotNull
private String name;
@Column(name = "description")
private String description;
@ManyToMany(cascade = {CascadeType.ALL})
@JoinTable(name="role_permission", schema=joinColumns={@JoinColumn(name="idPermission")}, inverseJoinColumns={@JoinColumn(name="idRole")})
private Set<Permission> roles=new HashSet();
With this I can avoid to create a new class for role_permission, but I dont know how to put created_at in this annotation. Is this possible?
I gave up and I used the intermediary. I just followed this tutorial and it works pretty well.
http://www.mkyong.com/hibernate/hibernate-many-to-many-example-join-table-extra-column-annotation/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With