0

There is a known hibernate bug https://hibernate.atlassian.net/browse/HHH-6221 where overlapping foreign keys triggers an AnnotationException. In @JoinColumns, you cannot have a mix of insertable and non-insertable @JoinColumn entries.

This has a workaround using @JoinColumnsOrFormulas, https://stackoverflow.com/a/13147366/16400385 .

The same bug is there for @Columns, but I can't find a @ColumnsOrFormulas annotation. Is there a similar workaround for @Columns ?

sample code

    @Columns( columns = {
        @Column(name = "currency_id", updatable = false, insertable = false),
        @Column(name = "fees")
    })
    private Money fees;

    @Columns( columns = {
            @Column(name = "currency_id"),
            @Column(name = "tax")
    })
    private Money tax;

the error I get is

'org.hibernate.AnnotationException: Mixing insertable and non insertable columns in a property is not allowed'

, same as HHH-6221

Muhammad Dyas Yaskur
  • 6,914
  • 10
  • 48
  • 73
cbf
  • 3
  • 1

1 Answers1

0

There is no workaround or anything for this as that kind of model simply is problematic/broken. One thing you could do is to map the individual columns in your entity and build a money instance through a @PostLoad listener.

Christian Beikov
  • 15,141
  • 2
  • 32
  • 58
  • Thanks! is that the right way to create a Money Value object with Hibernate? https://martinfowler.com/eaaCatalog/money.html . While my annotations could certainly be problematic or broken, the concept of a Money Value Object is not. – cbf Sep 13 '21 at 14:47
  • Sure, the concept is totally fine, but the mapping simply isn't how about you keep the mapping the way you have it, with the only adjustment being, that you have a dedicated column for the currency per attribute. This would work for Hibernate as well. – Christian Beikov Sep 13 '21 at 14:50