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?