Results 1 to 4 of 4
  1. #1
    jsnpereira is offline Member
    Join Date
    Apr 2011
    Posts
    1
    Rep Power
    0

    Default 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.
    Java Code:
    lorg.hibernate.MappingException: Unknown entity: Persistencia.Cadastro
    Annotation in the class
    Java 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
    Java 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
    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!

  2. #2
    shnplr is offline Member
    Join Date
    May 2011
    Posts
    6
    Rep Power
    0

    Default

    You need Cadastro.hbm.xml?

  3. #3
    foo123 is offline Member
    Join Date
    May 2011
    Posts
    10
    Rep Power
    0

    Default

    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

  4. #4
    sibernewf is offline Member
    Join Date
    Mar 2011
    Posts
    48
    Rep Power
    0

    Default

    Also does your project use persistence.xml? If so, ensure your class is included in there.

Similar Threads

  1. Replies: 1
    Last Post: 11-19-2010, 05:09 PM
  2. Mark Dexter persistence tutorial Junit problems
    By sonny in forum New To Java
    Replies: 9
    Last Post: 05-24-2010, 04:09 PM
  3. Replies: 2
    Last Post: 04-21-2010, 06:34 PM
  4. Hibernate Java Persistence
    By JavaBean in forum Java Tutorial
    Replies: 0
    Last Post: 09-22-2007, 10:02 PM
  5. Problems with hibernate in jsp
    By bbq in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 07-04-2007, 09:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •