Results 1 to 4 of 4
Thread: Problems persistence Hibernate
- 04-17-2011, 06:46 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 1
- Rep Power
- 0
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.
Annotation in the classJava Code:lorg.hibernate.MappingException: Unknown entity: Persistencia.Cadastro
configuration of the hibernate.cfg.xmlJava 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; } }
ServletJava 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>
Java 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!
- 05-07-2011, 07:07 PM #2
Member
- Join Date
- May 2011
- Posts
- 6
- Rep Power
- 0
You need Cadastro.hbm.xml?
- 05-17-2011, 10:40 AM #3
Member
- Join Date
- May 2011
- Posts
- 10
- Rep Power
- 0
the class needs to be inside package folder Persistencia.
since u use annotations i think hbm.xml is not necessary. as i understand it the class is not in the right package/folder
and you should add package Persistencia at the beginning of your class. i think this is the problem
- 08-01-2011, 03:23 AM #4
Member
- Join Date
- Mar 2011
- Posts
- 46
- Rep Power
- 0
Similar Threads
-
Any persistence framework better than hibernate
By amitsingh08 in forum JDBCReplies: 1Last Post: 11-19-2010, 05:09 PM -
Mark Dexter persistence tutorial Junit problems
By sonny in forum New To JavaReplies: 9Last Post: 05-24-2010, 04:09 PM -
Persistence causing problems with JButton 2D Array
By easyp in forum New To JavaReplies: 2Last Post: 04-21-2010, 06:34 PM -
Hibernate Java Persistence
By JavaBean in forum Java TutorialReplies: 0Last Post: 09-22-2007, 10:02 PM -
Problems with hibernate in jsp
By bbq in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 07-04-2007, 09:05 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks