How to prevent Hibernate from nullifying relationship column during entity removal -


I have two entities, A and B. I need to easily recover the entities, I value the value of some columns (some from A to some columns in column B). These columns are not primary or foreign keys, they contain only one business data, I need access to the collection of B. with the same value of this column from each instance of A. So I model it like this:

  class A {@OneToMany @JoinColumn (name = "column_in_B", referenced column name = "column_in_a") archive & lt; B & gt; Bs;  

In this way, I can run a question like "A one exam fetch a.bs b where b ...." (In fact, the real relationships are many-to-many .) But when I use @ManyToMany, being in hibernation forced me to join the table of joining, which is not present here. That's why I have to use @OneToMany as a workaround). So far, so good. The main problem is that whenever I remove an example of A, set the "caller_inb = empty" update call, because it thinks that column_in_B is a primary key in A (and because the line is deleted in A , It tries) Clean the foreign key in B) but column_in_B is not a foreign key, and can not be modified because it loses data (and this column is not taped in my case anyway , Where data integrity can be an exception).

Plese help me with this how to model this kind of relationship with Hibernate? (I call it "virtual relationships", or "secondary relationships" or otherwise because they are not based on foreign keys, they are just a few shortcuts that allow them to retrieve related objects and queue them with HQL Based on this, it seems that it is possible with XML mapping, annotation is possible.

Unfortunately, at the time of writing, hibernate Received annotation does not support joining position arbitrary summed up with sources. The group of properties was also not possible under the reference name.


Comments