使用@JoinColumnsOrFormulas和mappedBy

时间:2014-10-09 16:19:43

标签: java hibernate jpa one-to-many many-to-one

我遇到以下代码的问题:

表FiBean:

@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:

@OneToMany(mappedBy="user1", cascade={CascadeType.PERSIST, CascadeType.MERGE})
private Collection<FiBean> listeUser1;

然后,发生此错误:

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

我在这里找到了一个解决方法(https://forum.hibernate.org/viewtopic.php?f=1&t=1010559,删除UserBean上的mappedBy),但为什么这段代码不起作用?

0 个答案:

没有答案