-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: unnecessary update for read-only collection of elements
PostPosted: Mon Feb 02, 2009 1:18 pm 
Newbie

Joined: Mon Jul 21, 2008 5:12 am
Posts: 13
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.