title: @ManyToMany, using a View
body: <p>I'm having troubles with a @ManyToMany property on my Entity 'Location'.
  The location contains a parent/child relationship with other Locations, so it basically represents a tree of locations.
  (Location A contains children A1, A2 and Location A2 contains another Location B, etc.)</p>
  
  <p>No rocket science.</p>
  
  <p>Since this is a well know 'tree' and Hibernate / JPA do not support Hierarchical queries, I've added a readonly ManyToMany relation 'allParents'. This collection contains, like the name already said, all parents going upwards in the tree.
  To achieve this, I've created a view which is used as jointable in the mapping.</p>
  
  <p>Also here, No rocket science. all works fine.</p>
  
  <p>Note that I never use Cascade operations.</p>
  
  <p>The problem arises when I want to delete a Location.
  This delete tries to delete also records in that jointable (which is indeed normally the case), but this obviously does not work on a view. (at least, not my view).</p>
  
  <p>So, I am looking for a way to mark this association read-only. 
  The @Immutable does not seem to do the job.</p>
  
  <p>(always getting the exception: org.postgresql.util.PSQLException: ERROR: cannot delete from view "allnamedparents")</p>
  
  <p>Can anyone point me in the right direction?</p>
  
  <p>Thanks in advance!</p>
  
  <pre><code>@Entity
  @Table(name = "location")
  public class Location extends AbstractAuditingEntity implements {
  
  
      @OneToMany()
      @JoinColumn(name = "parent_id", foreignKey = @ForeignKey(name = "FK_location_parent"))
      private Set&lt;AbstractLocation&gt; childLocations = new LinkedHashSet&lt;&gt;();
  
  
      @Column(name="parent_id", updatable = false,insertable = false)
      private Long parentId;
  
      @Immutable()
      @ManyToMany()
      @JoinTable(
              name = "allnamedparents",
              joinColumns = {@JoinColumn(name = "locationid", referencedColumnName = "id")},
              inverseJoinColumns = {@JoinColumn(name = "parentid", referencedColumnName = "id")}
              )
      private List&lt;AbstractLocation&gt; allParents = new ArrayList&lt;&gt;();
  
  
  
  }
  </code></pre>