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);

希望我只是缺少一些简单的东西。

4

1 回答 1

2

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

于 2013-01-10T09:03:28.643 回答