Hibernate derived property with xml mapping

后端 未结 2 1343
北恋
北恋 2021-01-19 14:08

I have a Detectable class with a Revisions set, which are Hibernate managed POJOs. I\'m also mapping my entities using hbm.xml files. Wh

相关标签:
2条回答
  • 2021-01-19 14:50

    I finally achieved it with this code:

    <property name="_LastRevisionDate"
            formula="(select MAX(rev.start_date) from trevision rev where rev.id_detectable = id_detectable and rev.status != 'DRAFT')"
            type="date" />
    

    Where id_detectable is my current entity key column.


    UPDATE

    Another workaround is to use a DB view to obtain the last revision date. Then, there's the choice to map the Entity against that view instead of the original table.

    0 讨论(0)
  • 2021-01-19 14:57

    What is the sql syntax error? Did you try replacing _Id with id?

    0 讨论(0)
提交回复
热议问题