问题
I have to join a entity with a view to retrieve some data into properties
<join table="XXVIEW" optional="true">
<key column="ID_ENT" />
<property name="Prop1" insert ="false" update ="false" />
<property name="Prop2" insert ="false" update ="false" />
<property name="Prop3" insert ="false" update ="false" />
</join>
But when i try to save (insert) it fails becouse it try to insert a record in XXVIEW with ID_Ent
I need to have some properties in this entity get from various calculations or joins and to have as single properties non in a object property like a component.
Can i skip this insert ??? or can i map this properties in other way?
This properties is in a joined subclass. TIA Adb
回答1:
Instead of marking it as optional you can try mark it as inverse http://nhibernate.info/doc/nh/en/index.html#mapping-declaration-join
inverse (optional - defaults to false): If enabled, Hibernate will not try to insert or update the properties defined by this join.
<join table="XXVIEW" inverse="true">
回答2:
You cannot save a record on a view, on your class try adding the mutable='false'
<class name="ActorView" mutable="false">
...
If you are trying to save back then I suspect you will need to forget about the view and turn it into a fully blown entity with collections defined.
来源:https://stackoverflow.com/questions/5535429/nhibernate-hibernate-avoid-insert-in-joined-table-or-view