Hibernate映射异常:一对多映射

时间:2013-12-05 20:57:39

标签: java hibernate web-applications

我正在尝试做一个简单的消息系统,我为映射得到了严重的hbernate错误。这是一个类的样本

@Entity    
public class SMS {

    @Id
    @GeneratedValue
    @Column(name = "sms_id")
    private int id;


    private Korisnik sender;


    private Korisnik receiver;

    private String text;

这是SMS类中的Korisnik类

@Entity
public class Korisnik {

    @Id
    @Column(name = "user_num")
    private int id;

    private String name;


    public int getNumber() {
        return id;
    }

我如何设置类以使其映射正确?

  

org.springframework.beans.factory.BeanCreationException:错误   创建名为'korisnikDaoImpl'的bean:注入自动装配   依赖失败;嵌套异常是   org.springframework.beans.factory.BeanCreationException:不能   autowire字段:private org.hibernate.SessionFactory   com.sendsms.dao.impl.KorisnikDaoImpl.sessionFactory;嵌套异常   是org.springframework.beans.factory.BeanCreationException:错误   在类路径中定义名为'sessionFactory'的bean   resource [com / sendsms / config / AppConfig.class]:调用init   方法失败;嵌套异常是org.hibernate.MappingException:   无法确定:com.sendsms.model.Korisnik的类型,在表格中:   用于列的SMS:[org.hibernate.mapping.Column(receiver)]

1 个答案:

答案 0 :(得分:0)

@ManyToOne添加到receiver实体的senderSMS字段中。如果要指定列,请使用@JoinColumn注释而不是@Column