gpt4 book ai didi

mysql - 组织.hibernate.MappingException : Unable to find column with logical name OnetoOne Mapping

转载 作者:行者123 更新时间:2023-11-29 05:21:03 26 4
gpt4 key购买 nike

我是 JPA 的新手。我在为我的类定义 OneToOne 双向流时遇到问题。

用户信息.java:

@Entity
@Table(name="UserInfo")
public class UserInfo {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer idUserInfo;
private String firstName;
private String lastName;


@OneToOne(mappedBy="UserInfo")
private LoginInfo loginInfo;

登录信息.java:

@Entity
@Table(name="LoginInfo")
public class LoginInfo {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer idLoginInfo;

@Column(name="emailId")
private String emailId;

//bidirectional one to one association to UserInfo
@OneToOne
@JoinColumn(name="emailId", referencedColumnName="loginInfo")
private UserInfo userInfo;


private String sessionId;
private String password;

这是创建这些表的 sql:

   CREATE TABLE `LoginInfo` (
`emailId` varchar(45) NOT NULL,
`idLoginInfo` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`idLoginInfo`),
UNIQUE KEY `emailId_UNIQUE` (`emailId`),
UNIQUE KEY `id_UNIQUE` (`idLoginInfo`)
);

DROP TABLE IF EXISTS `UserInfo`;
CREATE TABLE `UserInfo` (
`idUserInfo` int(11) NOT NULL AUTO_INCREMENT,
`firstName` varchar(45) NOT NULL,
`lastName` varchar(45) NOT NULL,
`loginInfo` varchar(45) NOT NULL,
PRIMARY KEY (`idUserInfo`),
UNIQUE KEY `idUserInfo_UNIQUE` (`idUserInfo`),
UNIQUE KEY `loginInfo_UNIQUE` (`loginInfo`),
CONSTRAINT `loginInfo` FOREIGN KEY (`loginInfo`) REFERENCES `LoginInfo` (`emailId`) ON DELETE CASCADE ON UPDATE CASCADE
);

当我启动 Tomcat 服务器时,我在 ContextInitialization 上收到以下异常。

Caused by: org.hibernate.MappingException: Unable to find column with logical name: loginInfo in org.hibernate.mapping.Table(UserInfo) and its related supertables and secondary tables

但该列确实存在于 UserInfo 表中。如果映射正确,有人可以帮助我吗?

谢谢

最佳答案

无效关联:@JoinColumn(name="emailId", referencedColumnName="loginInfo")

@Entity
@Table(name="UserInfo")
public class UserInfo {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer idUserInfo;
private String firstName;
private String lastName;

@OneToOne(mappedBy = "userInfo", cascade = CascadeType.ALL)
private LoginInfo loginInfo;


@Entity
@Table(name="LoginInfo")
public class LoginInfo {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer idLoginInfo;

@Column(name="emailId")
private String emailId;

//bidirectional one to one association to UserInfo
@OneToOne
@PrimaryKeyJoinColumn
private UserInfo userInfo;


private String sessionId;
private String password;

关于mysql - 组织.hibernate.MappingException : Unable to find column with logical name OnetoOne Mapping,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25760492/

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