I’m trying to use hibernate in eclipse IDE, I have reverse engineered POJO class successfully. But it shows an error in hibernate configuration under session factory.
hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">1234</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/customer</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<mapping class="com.example.pojo.Customer"/>
<mapping resource="com/example/pojo/Customer.hbm.xml"/>
</session-factory>
</hibernate-configuration>
hibernate.reveng.xml
<?xml version="1.0" encoding="UTF-8"?>
<hibernate-reverse-engineering>
<table-filter match-catalog="customer" match-name="customer" />
<table catalog="customer" name="customer">
<column name="id"></column>
<column name="firstName"></column>
<column name="cuscol"></column>
<column name="lastName"></column>
<column name="birthDate"></column>
<column name="email"></column>
</table>
</hibernate-reverse-engineering>
Customer Pojo
public class Customer implements java.io.Serializable {
private int id;
private String firstName;
private String cuscol;
private String lastName;
private Date birthDate;
private String email;
public Customer() {
}
public Customer(int id) {
this.id = id;
}
public Customer(int id, String firstName, String cuscol, String lastName, Date birthDate, String email) {
this.id = id;
this.firstName = firstName;
this.cuscol = cuscol;
this.lastName = lastName;
this.birthDate = birthDate;
this.email = email;
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public String getFirstName() {
return this.firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getCuscol() {
return this.cuscol;
}
public void setCuscol(String cuscol) {
this.cuscol = cuscol;
}
public String getLastName() {
return this.lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Date getBirthDate() {
return this.birthDate;
}
public void setBirthDate(Date birthDate) {
this.birthDate = birthDate;
}
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
}
customer.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated Jul 20, 2016 4:45:13 PM by Hibernate Tools 4.0.0 -->
<hibernate-mapping>
<class name="Customer" table="customer" catalog="customer">
<id name="id" type="int">
<column name="id" />
<generator class="assigned" />
</id>
<property name="firstName" type="string">
<column name="firstName" length="45" />
</property>
<property name="cuscol" type="string">
<column name="cuscol" length="45" />
</property>
<property name="lastName" type="string">
<column name="lastName" length="45" />
</property>
<property name="birthDate" type="date">
<column name="birthDate" length="10" />
</property>
<property name="email" type="string">
<column name="email" length="45" />
</property>
</class>
</hibernate-mapping>
Update mapping entry in customer.hbm.xml like this -
<class="com.example.pojo.Customer" table= "customer"/>