2013-01-09 157 views
2

我有以下错误的问题:休眠双向多对一

Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/library.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: A Foreign key refering tv.mirada.connect.cashless.parking.model.PaymentInterface from tv.mirada.connect.cashless.parking.model.Merchant has the wrong number of column. should be 0 

我花了大约一天寻找答案,并试图东西,没有运气。我实际上并不需要双向访问,我只需要能够从payment_interface获得商家表格行,但是包含双向表单比试图从单向到单向更简单。

我使用的表格是商家表和付款接口表。我意识到我可以让商户表直接引用节点表,但商家表在支付界面中具有信息的扩展,因此以这种方式映射它是更有意义的。

@Entity 
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY) 
@Table(name = "park_merchant") 
public class Merchant implements java.io.Serializable { 

    @Id 
    @GeneratedValue 
    @Column(name="id", unique=true, nullable=false) 
    private Integer id; 

    @ManyToOne(fetch = FetchType.LAZY) 
    @JoinColumn(name="payment_interface_node_id", nullable = false) 
    private PaymentInterface paymentInterface; 


@Entity 
@Table(name = "park_payment_interface", uniqueConstraints = @UniqueConstraint(columnNames = "name")) 
public class PaymentInterface implements java.io.Serializable { 

    @Id 
    @OneToOne(fetch=FetchType.LAZY, cascade=CascadeType.ALL) 
    @JoinColumn(name = "node_id", unique = true, nullable = false) 
    private Node node; 

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "paymentInterface") 
    private Set<Merchant> merchants = new HashSet<Merchant>(0); 

希望我只是想念一些简单的东西。

回答

2

啊,找到了解决办法。我需要将@ManyToOne和@JoinColumn放在getter的Merchant表中,而不是放在变量声明中。我仍然不确定为什么,但至少现在我知道了。