Nhibernate/hibernate Avoid Insert in joined table or view

為{幸葍}努か 提交于 2019-12-24 07:13:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!