I have found a lot of questions on SO with this error message but unfortunately (fortunately for people who previously had this issue) they all were missing the column they intended to map. I have two classes ResetPin and User and would like to establish OneToOne mapping between ResetPin and User.email
But whenever I run my project I get the following error message:
Caused by: org.hibernate.MappingException: Unable to find column with logical name: email in org.hibernate.mapping.Table(users) and its related supertables and secondary tables
at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:582)
at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:258)
at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:116)
at org.hibernate.cfg.Configuration.processEndOfQueue(Configuration.java:1598)
at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1521)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1422)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:852)
Below are my classes:
ResetPin class:
public class ResetPin implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "email", referencedColumnName = "email")
private User user;
@NotNull
@Size(min = 5, max = 50)
@Column(name = "token")
private String token;
@Column(name = "active")
private Boolean active;
//Getters and setters
.
.
.
.
}
User class:
public class User implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Integer id;
@Column(name = "name")
private String name;
@NotNull
@Size(min = 5, max = 50)
@Column(name = "email", unique = true)
private String email;
@NotNull
@Size(min = 5, max = 50)
@Column(name = "password")
private String password;
//Getters and setters
.
.
.
.
}
referencedColumnName refers to the name of the column representing the association in the other table (in your case User) and it should map to the primary key
@JoinColumn(name = "email", referencedColumnName = "id")
It is by default referencing to the primary key unless you have a composite key then you need to use it, so in your case its enough like this
@JoinColumn(name = "email")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With