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.  [ 4 posts ] 
Author Message
 Post subject: org.hibernate.MappingException: Unknown entity error
PostPosted: Sat Jun 26, 2010 3:45 pm 
Newbie

Joined: Sat Jun 26, 2010 3:30 pm
Posts: 1
Hi, I am new to Hibernate. I am getting org.hibernate.MappingException: Unknown entity error during the session.save(obj).
I have placed the mapping entries in hbm.xml. It worked fine for one program, but giving an error for the second program.

This is how my program looks:

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.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@udaykiran-pc:1521:xe</property>
<property name="hibernate.connection.username">system</property>
<property name="hibernate.connection.password">addepalli</property>

<!-- Mapping files -->
<mapping resource="contact.hbm.xml"/>
<!--mapping resource="../../contact.hbm.xml"/--></session-factory>
</hibernate-configuration>

contact.hbm.xml
-----------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.sample.hibernate.Book" table="BOOK">
<id name="bookId" type="long" column="ID"><generator class="increment"/></id>
<property name="bookName"><column name="BOOKNAME"/></property>
</class>
</hibernate-mapping>

Book.java
----------
public class Book {

private long bookId;
private String bookName;

public String getBookName() {
return bookName;
}

public void setBookName(String bookName) {
this.bookName = bookName;
}

public long getBookId() {
return bookId;
}

public void setBookId(long bookId) {
this.bookId = bookId;
}

}

IncrSampleHibernate.java
--------------------------
public class IdIncrSampleHibernate {

public static void main(String args[]) {
Session session = null;

SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();

System.out.println("Inserting book obj into database");
Book book = new Book();

book.setBookName("Hibernate Tutorial");
session.save(book);
System.out.println("Book obj saved to database");

tx.commit();
session.flush();
session.close();
}
}

Exception:
----------

init:
deps-module-jar:
deps-ear-jar:
deps-jar:
compile-single:
run-main:
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.5
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : contact.hbm.xml
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: com.sample.hibernate.Contact -> CONTACT
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
27 Jun, 2010 1:13:38 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
27 Jun, 2010 1:13:38 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
27 Jun, 2010 1:13:38 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
27 Jun, 2010 1:13:38 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@udaykiran-pc:1521:xe
27 Jun, 2010 1:13:38 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=system, password=****}
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: Oracle, version: Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: Oracle JDBC driver, version: 10.1.0.5.0
27 Jun, 2010 1:13:38 AM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.OracleDialect
27 Jun, 2010 1:13:38 AM org.hibernate.dialect.Oracle9Dialect <init>
WARNING: The Oracle9Dialect dialect has been deprecated; use either Oracle9iDialect or Oracle10gDialect instead
27 Jun, 2010 1:13:38 AM org.hibernate.dialect.OracleDialect <init>
WARNING: The OracleDialect dialect has been deprecated; use Oracle8iDialect instead
27 Jun, 2010 1:13:38 AM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
27 Jun, 2010 1:13:38 AM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
27 Jun, 2010 1:13:38 AM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
27 Jun, 2010 1:13:38 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
27 Jun, 2010 1:13:38 AM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
27 Jun, 2010 1:13:39 AM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Inserting book obj into database
Exception in thread "main" org.hibernate.MappingException: Unknown entity: com.sample.hibernate.Book
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:550)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1338)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:98)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
at com.sample.hibernate.IdIncrSampleHibernate.main(IdIncrSampleHibernate.java:31)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)


Top
 Profile  
 
 Post subject: Re: org.hibernate.MappingException: Unknown entity error
PostPosted: Tue Jul 20, 2010 12:11 am 
Newbie

Joined: Mon Jul 19, 2010 6:25 pm
Posts: 1
Hey there, I am also experiencing a similar problem. The exception is thrown on a save or get...

Can you tell me if in your case, the program is failing regardless of environment?

For me, everything compiles and executes with the desired results on my local (development) machine which is a Mac running OSX Tiger and Java 1.5, however when JAR'd and deployed onto the Ubuntu 8.10 server, the following exception is thrown. Database is MySQL 5.0.67

Code:
org.hibernate.MappingException: Unknown entity: persistence.ifms.clear.IfmsClearPrEntity
        at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:550)
        at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:68)
        at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
        at org.hibernate.impl.SessionImpl.get(SessionImpl.java:815)
        at org.hibernate.impl.SessionImpl.get(SessionImpl.java:808)
        at persistence.ifms.clear.IfmsClearDAO.get(IfmsClearDAO.java:44)
        at Tester.testGet(Tester.java:22)
        at Tester.main(Tester.java:14)
java.lang.Exception: Could not find the record 
Unknown entity: persistence.ifms.clear.IfmsClearPrEntity
        at persistence.ifms.clear.IfmsClearDAO.get(IfmsClearDAO.java:51)
        at Tester.testGet(Tester.java:22)
        at Tester.main(Tester.java:14)


It's terribly frustrating at the moment as I've checked mappings, required JAR/Libs, NULL value handling, etc.


Top
 Profile  
 
 Post subject: Re: org.hibernate.MappingException: Unknown entity error
PostPosted: Wed Jul 21, 2010 6:42 am 
Senior
Senior

Joined: Tue Oct 28, 2008 10:39 am
Posts: 196
Your stacktrace shows that you are mapping a class named Contact: "Mapping class: com.sample.hibernate.Contact -> CONTACT"
Your source says that Contact.hbm.xml is mapping a class named Book. Check it again, something's wrong there. Does contact.hbm.xml really reside in the src-folder?


Top
 Profile  
 
 Post subject: Re: org.hibernate.MappingException: Unknown entity error
PostPosted: Wed Sep 29, 2010 11:37 pm 
Newbie

Joined: Wed Sep 29, 2010 12:28 am
Posts: 3
Hi

I am new to Hibernate. I am using Hibernate 3.3.1 with Jboss 5.

I copied hibernate configuration file and mapping file into ../server/sample/conf directory. And classes files located at ../server/sample/deploy/sample.war/WEB-INF/classes directory.

I am getting same exception(org.hibernate.MappingException: Unknown entity:) when i calling Hibernate from my application. Please help me to resolve this issue.

I tried to copy the mapping file to class file location, but no help.

Hibernate configuration file

Code:
<?xml version='1.0' encoding='utf-8'?>
<hibernate-configuration>
  <session-factory>
    <property name=“connection.datasource">java:sampleDB</property>
    <property name="connection.autocommit">false</property>
    <property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
    <property name="show_sql">false</property>
    <property name="jdbc_use_streais_fbr_binary'>true</property>
    <property name="max_fetch_depth">3</property>
    <property name="cache.use_second_level_cache">False</property>
    <property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
    <!-- Mapping files -->
    <mapping resource=“sampleLookupGenericData.hbm.xml"/>
  <session-factory>
</hibernate-configuration>


My hibernate mapping file

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
  <sql-query name="sampleloopup">
    <return alias="generic" class="com.test.sample.portal.data.SampleLookupGenericData“></return>
        SELECT PROJ_NAME as generic.lookUpDescriptionkesult test_Sample_PROJECT
        where PROJ_ID = ?
  </sql-query>
</hibernate-mapping>



Log details

Code:
[ReguestListenerlnterface] registered Tistener interface
[RequestListenerInter ace name=INewBrowserwindoNListener, method=public abstract
apache.wicket.markup.html.INewBrowserwindowListener.onNewBrowserwindow()]
[STDOUT] **** Input value was *******sample
[STDOUT] Query Name has to execute ~->sampleloopup
[Environment] Hibernate 3.3.1.GA
[Environment] hibernate.properties not found
[Environment] Bytecode provider name : javassist
[Environment] using JDK 1.4 ;ava.sql.Timestamp handling
[Confiuration] configuring from resource:hibernate-sampledb.cfg.xml
INFO [Configuration] Configuration resource: hibernate-sampledb.cfg.xml
[Confi uration] Reading mappings from resource : SampleLookupGenericData.hgm.xml
[configuration] Configured SessionFactory: null
[NamingHelper] JNDI InitialContext properties:{}
[batasourceconnectionProviderl Using datasource: java:sampleDB
[SettingsFactory] RDBMS: Microsoft SQL server, version: 9.00.4305
[SettingsFactory] JDBC driver: Microsoft SQL Server JDBC Driver
[Dialect]_Using dialect: org.hibernate.dialect.SQLServerDialect
[TransactionFactoryFactory] Transaction strategy:
org.hibernate.transaction.JTATransactionFactory
[NamingHelper] JNDI InitialContext properties:{}
[TransactionManagerLookupFactory] No TransactionManagerLookup
configured (in JTA environment, use of read-write or transactional second-level
cache is not recommended)
SettingSFactory] Automatic flush during beforeCompletion():disabled
[SettingsFactory] Automatic session close at end of transaction:
disabled
[SettingsFactory] Scrollable resuit sets: enabled
[SettingsFactory] JDBC3 getGeneratedKeys(): enabied
[SettingsFactory] Connection release mode: auto
[SettingsFactory] Maximum outer join fetch depth: 3
[SettingsFactory] Defauit batch fetch size: 1
[SettingsFactory] Generate SQL with comments: disabied
[SettingsFactory] Order SQL updates by primary key: disabied
[SettingsFactory] Order SQL inserts for batching: disabied
[SettingsFactory] Query translator:org.hibernate.hql.ast.ASTQueryTranslatorFactory
[ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
[SettingsFactory] Query language substitutions: {}
[SettingsFactory] JPA-QL strict compiiancez disabied
[SettingsFactory] Second-leve cache: disabied
[SettingsFactory] Query cache: disabied
[SettingsFactory] Cache region factory :
org.hibernate.cache.impl.NoCachingRegionFactory
[SettingsFactory] Optimize cache for minimai puts: disabled
[SettingsFactory] Structured second-level cache entries: disabled
[SettingsFactory] Statistics: disabied
[SettingsFactory] Deleted entity synthetic identifier rollback:disabled
[SettingsFactory] Defauit entity-mode: pojo
[SettingsFactory] Named query checking : enabied
[SessionFactoryImpl] building session factory
[SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
SEVERE [SessionFactoryImpl] Error in named query: sampleloopup
org.hibernate.MappingException: Unknown entity: com.test.sample.portal.data.SampleLookupGenericData
at
org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:580)



Thanks in Advance for your Help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.