gpt4 book ai didi

java - Hibernate映射异常: One to None Mapping

转载 作者:太空宇宙 更新时间:2023-11-04 15:20:49 25 4
gpt4 key购买 nike

我正在尝试做一个简单的消息系统,但我遇到了严重的映射错误。这是类的示例

@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: Error creating bean with name 'korisnikDaoImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.sendsms.dao.impl.KorisnikDaoImpl.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [com/sendsms/config/AppConfig.class]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Could not determine type for: com.sendsms.model.Korisnik, at table: SMS, for columns: [org.hibernate.mapping.Column(receiver)]

最佳答案

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

关于java - Hibernate映射异常: One to None Mapping,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20410537/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com