Hibernate version: hibernate-3.2.6.ga, hibernate-annotations-3.3.1.ga
Name and version of the database you are using: MS SQL 2005
I have two classes - User and Role.
They are many-to-many relationship, but i need to link them only by ID.
So - i have created table and make a reference by this code:
Code:
USER.JAVA:
@CollectionOfElements
@JoinTable(
name="user_roles",
joinColumns = @JoinColumn(name="user_id", nullable=false, insertable=false, updatable=false)
)
@Column(name="role_id", nullable=false, insertable=false, updatable=false)
private Set<Long> roleIds = new HashSet<Long>();
And the same logic in Role.java, except the updatable=true,insertable=true.
But if i change roleIds collection in user - Hibernate tries to insert corresponding values in user_roles table and failed with duplicate key exception.
Question:
How to specify that this collection should be only loaded from databse, but any change should be ignored?