-->
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: Make a collection readonly
PostPosted: Wed Sep 26, 2012 1:31 pm 
Beginner
Beginner

Joined: Tue Oct 30, 2007 7:57 am
Posts: 47
I am writing an app with JPA2 implemented by hibernate 4.1.7

In the entity there is a @ManyToMany collection that reads its data from a database view (VBRGEI_UNIDADESVALIDAS). As a result, the data is strictly read-only

Code:
   @ManyToMany   
   @JoinTable(name="VBRGEI_UNIDADESVALIDAS",       
      joinColumns={
         @JoinColumn(name="id_unidad", referencedColumnName="id_unidad", insertable=false, updatable=false)
      },
      inverseJoinColumns={
         @JoinColumn(name="id_unidad_valida", referencedColumnName="id_unidad", insertable=false, updatable=false)
      })
   @Immutable
   private Set<TblgeiUnidad> unidadesValidas;


The problem I have is that when I merge the entity for update, hibernate tries to update de data in the view.

When I update the entity, the collection "unidadesValidas" is null, so hibernate tries to delete registers from VBRGEI_UNIDADESVALIDAS, and I get an error.

The only solution I found, is to load the original data from database, and copy the collection value, but I'd like a way to tell hibernate "This collection is read-only, ignore for updates". I have worked with views before, and never had issues of this type. The difference is that I always mapped the view in a separate entity, and never used a @JoinTable

Any way to mark the collection as read-only?


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.