Using @JoinColumnsOrFormulas and mappedBy
I have a problem with the following code:
FiBean table:
@JoinColumnsOrFormulas({
@JoinColumnOrFormula(column = @JoinColumn(name = "TRI", referencedColumnName = "TRI", nullable = false, insertable = false, updatable = false)),
@JoinColumnOrFormula(formula = @JoinFormula(value = "USER1", referencedColumnName = "CODE"))
})
private UserBean user1;
UserBean table:
@OneToMany(mappedBy="user1", cascade={CascadeType.PERSIST, CascadeType.MERGE})
private Collection<FiBean> listeUser1;
Then this error occurs:
Caused by: java.lang.ClassCastException: org.hibernate.mapping.Formula
at org.hibernate.cfg.annotations.TableBinder.bindFk(TableBinder.java:352)
at org.hibernate.cfg.annotations.CollectionBinder.bindCollectionSecondPass(CollectionBinder.java:1423)
at org.hibernate.cfg.annotations.CollectionBinder.bindOneToManySecondPass(CollectionBinder.java:733)
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:666)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:619)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:66)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1221)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:383)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1206)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1459)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:193)
Hibernate v3.5.6 JDK 5 Tomcat 5.5
I found a workaround here ( https://forum.hibernate.org/viewtopic.php?f=1&t=1010559 by removing mappedBy on the UserBean) but why doesn't this code work?
+3
source to share
No one has answered this question yet
Check out similar questions: