Hibernate and @JoinFormula: org.hibernate.mapping.Formula cannot be cast to org.hibernate.mapping.Column

后端 未结 3 811
攒了一身酷
攒了一身酷 2020-12-17 09:36

I\'m trying to write a hibernate adapter for an old database schema. This schema does not have a dedicated id column, but uses about three other columns to join data.

<
3条回答
  •  一个人的身影
    2020-12-17 10:22

    Join formulas are very fragile in Hibernate for the time being; I always had a difficult time to get them work properly.

    The workaround that helped me often was to create database views which exposed the proper columns (including foreign keys that don't exist in the original tables). Then I mapped the entities to the views using classing Hibernate/JPA mappings.

    Sometimes there are redundant joins in the generated SQL when using such entities, but the database optimizes such queries in most cases so that the execution plan is optimal anyway.

    Another approach could be using @Subselects, which are some kind of Hibernate views, but I expect them to be less performant than the classic database views.

提交回复
热议问题