These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: org.hibernate.MappingException: Unknown entity?
PostPosted: Fri Aug 31, 2012 8:31 pm 
Newbie

Joined: Fri Aug 31, 2012 7:50 pm
Posts: 2
Hi,

I am new to hibernate and have just been trying out an online tutorial. And am getting the following errors

Code:
109 [main] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final
109 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.6.10.Final
109 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
109 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
109 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
171 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /com/hiber/users/hibernate.cfg.xml
171 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /com/hiber/users/hibernate.cfg.xml
234 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : com/hiber/users/users.hbm.xml
312 [main] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
343 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: users -> users
375 [main] INFO org.hibernate.cfg.Configuration - Hibernate Validator not found: ignoring
375 [main] INFO org.hibernate.cfg.search.HibernateSearchEventListenerRegister - Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
375 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
375 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 20
375 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
375 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://localhost/goDB
375 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=root, password=****}
609 [main] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
625 [main] INFO org.hibernate.engine.jdbc.JdbcSupportLoader - Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
625 [main] INFO org.hibernate.cfg.SettingsFactory - Database ->
       name : MySQL
    version : 5.5.27
      major : 5
      minor : 5
625 [main] INFO org.hibernate.cfg.SettingsFactory - Driver ->
       name : MySQL-AB JDBC Driver
    version : mysql-connector-java-5.1.12 ( Revision: ${bzr.revision-id} )
      major : 5
      minor : 1
625 [main] INFO org.hibernate.transaction.TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
625 [main] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
625 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
625 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
625 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
625 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled
625 [main] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
625 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enabled
625 [main] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
625 [main] INFO org.hibernate.cfg.SettingsFactory - Maximum outer join fetch depth: 2
625 [main] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
625 [main] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
625 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
625 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
625 [main] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
625 [main] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
625 [main] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
625 [main] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: disabled
625 [main] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
625 [main] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
625 [main] INFO org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
625 [main] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
625 [main] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
625 [main] INFO org.hibernate.cfg.SettingsFactory - Echoing all SQL to stdout
625 [main] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled
625 [main] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
625 [main] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
625 [main] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled
625 [main] INFO org.hibernate.cfg.SettingsFactory - Check Nullability in Core (should be disabled when Bean Validation is on): enabled
640 [main] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
656 [main] INFO org.hibernate.type.BasicTypeRegistry - Type registration [wrapper_characters_clob] overrides previous : org.hibernate.type.CharacterArrayClobType@1490eb5
656 [main] INFO org.hibernate.type.BasicTypeRegistry - Type registration [materialized_clob] overrides previous : org.hibernate.type.MaterializedClobType@164b09c
656 [main] INFO org.hibernate.type.BasicTypeRegistry - Type registration [characters_clob] overrides previous : org.hibernate.type.PrimitiveCharacterArrayClobType@186f247
656 [main] INFO org.hibernate.type.BasicTypeRegistry - Type registration [clob] overrides previous : org.hibernate.type.ClobType@8c4a77
656 [main] INFO org.hibernate.type.BasicTypeRegistry - Type registration [java.sql.Clob] overrides previous : org.hibernate.type.ClobType@8c4a77
656 [main] INFO org.hibernate.type.BasicTypeRegistry - Type registration [wrapper_materialized_blob] overrides previous : org.hibernate.type.WrappedMaterializedBlobType@6d0040
656 [main] INFO org.hibernate.type.BasicTypeRegistry - Type registration [materialized_blob] overrides previous : org.hibernate.type.MaterializedBlobType@2b9406
656 [main] INFO org.hibernate.type.BasicTypeRegistry - Type registration [blob] overrides previous : org.hibernate.type.BlobType@1035079
656 [main] INFO org.hibernate.type.BasicTypeRegistry - Type registration [java.sql.Blob] overrides previous : org.hibernate.type.BlobType@1035079
859 [main] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
Hibernate: select users0_.id as id0_, users0_.userName as userName0_, users0_.pin as pin0_, users0_.password as password0_, users0_.firstName as firstName0_, users0_.lastName as lastName0_, users0_.emailAddress as emailAdd7_0_, users0_.zipCode as zipCode0_, users0_.status as status0_ from users users0_
11 Mike
12 Mike
13 Trent
14 Alejandro
15 Matt
16 Ethan
17 Mike
18 Jeff
org.hibernate.MappingException: Unknown entity: com.hiber.users.users
   at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:693)
   at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:92)
   at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090)
   at org.hibernate.impl.SessionImpl.get(SessionImpl.java:1005)
   at org.hibernate.impl.SessionImpl.get(SessionImpl.java:998)
   at com.hiber.users.test.deleteCourse(test.java:49)
   at com.hiber.users.test.main(test.java:17)


Here are my config files

hibernate.cfg.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
      "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
      "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
        <property name="hibernate.connection.password">gooch123</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost/goDB</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
        <property name="show_sql">true</property>
        <mapping resource="com/hiber/users/users.hbm.xml"/>
    </session-factory>
</hibernate-configuration>


users.hbm.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class entity-name="users" name = "com.hiber.users.users" table="users">
  <meta attribute="description">This class is used to save the info about users in the users table</meta>
  <id column="id" name="id" type="long"/>
  <property column="userName" name="userName" type="string"/>
  <property column="pin" name="pin" type="int"/>
  <property column="password" name="password" type="string"/>
  <property column="firstName"  name="firstName" type="string"/>
  <property column="lastName"  name="lastName" type="string"/>
  <property column="emailAddress" name="emailAddress" type="string"/>
  <property column="zipCode" name="zipCode" type="string"/>
  <property column="status" name="status" type="string"/>
</class>
</hibernate-mapping>


Here are my other files

users.java
Code:

package com.hiber.users;

//Generated Aug 31, 2012 3:55:15 PM by Hibernate Tools 3.4.0.CR1

/**
* users generated by hbm2java
*/
public class users implements java.io.Serializable {

   private long id;
   private String userName;
   private int pin;
   private String password;
   private String firstName;
   private String lastName;
   private String emailAddress;
   private String zipCode;
   private String status;

   public users() {
   }

   public users(long id) {
      this.id = id;
   }

   public users(long id, String userName, int pin, String password,
         String firstName, String lastName, String emailAddress,
         String zipCode, String status) {
      this.id = id;
      this.userName = userName;
      this.pin = pin;
      this.password = password;
      this.firstName = firstName;
      this.lastName = lastName;
      this.emailAddress = emailAddress;
      this.zipCode = zipCode;
      this.status = status;
   }

   public long getId() {
      return this.id;
   }

   public void setId(long id) {
      this.id = id;
   }

   public String getUserName() {
      return this.userName;
   }

   public void setUserName(String userName) {
      this.userName = userName;
   }

   public int getPin() {
      return this.pin;
   }

   public void setPin(int pin) {
      this.pin = pin;
   }

   public String getPassword() {
      return this.password;
   }

   public void setPassword(String password) {
      this.password = password;
   }

   public String getFirstName() {
      return this.firstName;
   }

   public void setFirstName(String firstName) {
      this.firstName = firstName;
   }

   public String getLastName() {
      return this.lastName;
   }

   public void setLastName(String lastName) {
      this.lastName = lastName;
   }

   public String getEmailAddress() {
      return this.emailAddress;
   }

   public void setEmailAddress(String emailAddress) {
      this.emailAddress = emailAddress;
   }

   public String getZipCode() {
      return this.zipCode;
   }

   public void setZipCode(String zipCode) {
      this.zipCode = zipCode;
   }

   public String getStatus() {
      return this.status;
   }

   public void setStatus(String status) {
      this.status = status;
   }

}


HibernateUtil.java
Code:
package com.hiber.util;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {
   private static final SessionFactory sessionFactory;
   static {
      try {
         sessionFactory = new Configuration().configure("/com/hiber/users/hibernate.cfg.xml").buildSessionFactory();
      } catch (Throwable ex) {
         System.err.println("Initial SessionFactory creation failed." + ex);
         throw new ExceptionInInitializerError(ex);
      }
   }

   public static SessionFactory getSessionFactory() {
      return sessionFactory;
   }
}


and finally test.java
Code:
package com.hiber.users;

import java.util.List;
import java.util.Iterator;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.hiber.util.HibernateUtil;

public class test {

   public static void main(String[] args) {
        test obj = new test();
      obj.listCourse();
      obj.deleteCourse(18);
   }

   public void listCourse()
   {
      Session session = HibernateUtil.getSessionFactory().openSession();
      Transaction transaction = null;
      try {
         transaction = session.beginTransaction();
         List courses = session.createQuery("from users").list();
         for (Iterator iterator = courses.iterator(); iterator.hasNext();)
         {
            users users1 = (users) iterator.next();
            System.out.println(users1.getId() + " " + users1.getFirstName());
         }
         transaction.commit();
      } catch (HibernateException e) {
         transaction.rollback();
         e.printStackTrace();
      } finally {
         session.close();
      }
   }



   public void deleteCourse(int UserId)
   {
      Session session = HibernateUtil.getSessionFactory().openSession();
      Transaction transaction = null;
      try {
         transaction = session.beginTransaction();
         users users1 = (users) session.get(users.class, UserId);
         session.delete(users1);
         transaction.commit();
      } catch (HibernateException e) {
         transaction.rollback();
         e.printStackTrace();
      } finally {
         session.close();
      }
   }
}


The odd thing is that listCourse works fine as seen in the output above but deleteCourse fails with the
unknown entity error. Like I said I have been googling for hours and as of yet haven't found anything.

Thanks in advance for any advice!


Top
 Profile  
 
 Post subject: Re: org.hibernate.MappingException: Unknown entity?
PostPosted: Fri Aug 31, 2012 8:41 pm 
Newbie

Joined: Fri Aug 31, 2012 7:50 pm
Posts: 2
Actually one thing to note I did use the code generation tool...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.