Problems persistence Hibernate
Hello, people!
i'm from brazilian, i know Wittes little english.
I am trying schedule hibernate in the linguage java. still is error execution. See message error bellow.
Code:
lorg.hibernate.MappingException: Unknown entity: Persistencia.Cadastro
Annotation in the class
Code:
@Entity
@Table(name="cadastro")
public class Cadastro {
@Id
@GeneratedValue
private int id;
@Column(name="n0me")
private String nome;
@Column(name="email")
private String email;
@Column(name="idade")
private int idade;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public int getIdade() {
return idade;
}
public void setIdade(int idade) {
this.idade = idade;
}
}
configuration of the hibernate.cfg.xml
Code:
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.connection.url">
jdbc:mysql://localhost/testehib
</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.connection.autocommit">true</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<mapping class="Persistencia.Cadastro"/>
</session-factory>
</hibernate-configuration>
Servlet
Code:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
SessionFactory sf = (new AnnotationConfiguration().configure("/CFG/hibernate.cfg.xml")).buildSessionFactory();
Session sessao = sf.openSession();
Transaction tx = null;
try {
tx = sessao.beginTransaction();
Cadastro cad = new Cadastro();
cad.setNome("Jeison Pereira");
cad.setIdade(28);
cad.setEmail("jsnpereira@gmail.com");
sessao.save(cad);
tx.commit();
} catch (HibernateException e) {
tx.rollback();
e.printStackTrace();
} finally{
sessao.close();
}
}
hope you help me for resolve this problem. thank you!