I am brand new to Hibernate and I am trying have created the following class, which I now want to generate the hibernate mappings for.
package com.simpleprogrammer;
public class User {
private int id;
private String name;
private int total;
private int goal;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getGoal() {
return goal;
}
public void setGoal(int goal) {
this.goal = goal;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
When I right-click on Persistence I expect to see "Generate Persistence Mappings" -> "By Hibernate Mappings" to be available. But it is not. All I can see is "By database schema". Does anybody know why "By Hibernate Mappings is not available?
Will supply more information if requested or required, I am following a pluralsight course which is approx 2 years out of date and using Eclipse, just to make things even more complex!
You need to add:
@Entity
at start of class:
@Entity
public class User {
@Id
private int id;
...
Then add <mapping class="com.simpleprogrammer.User"/>
to hibernate.cfg.xml
before closing of element </session-factory>
also med sure that you add ID annotation (@Id
) to variable id.