私のプロジェクトでは、1対1の外部キー関係マッピングに問題があります。1対1の外部キー
User.java
@Access(AccessType.FIELD)
@Entity
@Table(name = "users")
public class User {
public Role ro;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public int user_id;
@Column(name = "username")
public String username;
@Column(name = "password")
public String password;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "username")
public Role getRo() {
return ro;
}
public void setRo(Role ro) {
this.ro = ro;
}
@Column(name = "enabled")
public int enabled;
public User() {
}
public int getUser_id() {
return user_id;
}
public User(String username, String password, int enabled) {
this.username = username;
this.password = password;
this.enabled = enabled;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getEnabled() {
return enabled;
}
public void setEnabled(int enabled) {
this.enabled = enabled;
}
@Override
public String toString() {
return String.format(
"student[id=%d, name='%s', age='%d']",
ro.getUsername(), username, ro.getUsername());
}
}
Role.java
import javax.persistence.*;
@Access(AccessType.FIELD)
@Entity
@Table(name = "user_roles")
public class Role {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public int user_role_id;
@Column(name = "username")
public String username;
@Column(name = "role")
public String role;
public User user;
@OneToOne(mappedBy = "ro")
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Role(String username, String role) {
this.username = username;
this.role = role;
}
public Role() {
}
public int getUser_role_id() {
return user_role_id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
}
これはエラーです:org.hibernate.MappingException:によって引き起こさ
COM:用のタイプを決定できませんでした。 [org.hibernate.mapping.Column(ro)] at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:431)〜[hibernate.mapping.Column(ro)]カラムのテーブル:usersのcompany.project.models.Roleは、コア- 5.0.12.Final.jar:5.0.12.Final] at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:398)〜[hibernate-core-5.0.12.Final.jar:5.0.12。最終結果] at org.hibernate.mapping.Property.isValid(Property.java:225)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final] at org.hibernate.mapping.PersistentClass。 (Hibernate-core-5.0.12.Final.jar:5.0.12.Final) at org.hibernate.mapping.RootClass.validate(RootClass.java:265)〜[hibernate- core-5.0.12.Final.jar:5.0.12.Final] at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:329)〜[hibernate-core-5.0.12.Final.jar: 5.0.12.Final] at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:443)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final] at org。 hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879)〜[休止状態-のEntityManager-5.0.12.Final.jar:5.0.12.Final] ... 22個の共通フレームが
すべての '@ Column'と' @ MappedBy'に変数、またはユーザーの 'Class'のゲッターのいずれかにアノテーションを付けてみてください。 –