-->
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:
PostPosted: Wed Feb 28, 2007 6:11 pm 
Beginner
Beginner

Joined: Thu Jun 17, 2004 10:08 am
Posts: 21
Location: Paris-France
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hello,
I'm using Spring LocalContainerEntityManagerFactoryBean class for creating an EntityManager. I know that the EntityManager is not null and seems to be ok but when i try to use it i have a "org.hibernate.MappingException: Unknown entity" exception.

The same entities are working ok on J2EE server (JBoss).

Hibernate version:
H3core 3-2, H3 annotations 3.2.1 GA, H3 entity manager 3.2.1 GA

persistence.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/ ... ce_1_0.xsd"
version="1.0">
<persistence-unit name="simplep" transaction-type="RESOURCE_LOCAL" >

<provider>org.hibernate.ejb.HibernatePersistence</provider>



<properties>
<property name="hibernate.archive.autodetection" value="class"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="use_sql_comments" value="true"/>
</properties>
</persistence-unit>
</persistence>

Mapping documents:
using annotations
Exemple of annotated class:
@Entity
@javax.persistence.Table(name = "dfTable")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "DISCRIMINATOR", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue("BaseTable")
public class BaseTable implements Serializable {

/**
*
*/
private static final long serialVersionUID = 4151185309718726372L;

private int id = 0;

/* used by jpa container */
BaseTable() {
}

public BaseTable(int id) {
this.id = id;
}


@Id
public int getId() {
return id;
}

@SuppressWarnings("unused")
private void setId(int newId) {
this.id = newId;
}


private String name = "";

@Column(name = "name")
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
........

Code between sessionFactory.openSession() and session.close():
using JPA

Full stack trace of any exception that occurs:
java.lang.IllegalArgumentException: Unknown entity: com.bo.df.designer.domain.BaseTable
at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:233)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:283)
at $Proxy8.merge(Unknown Source)
at com.bo.df.designer.dao.jpa.J2SEJPADataAccess.save(J2SEJPADataAccess.java:35)
at com.bo.df.designer.domain.PersistenceService.save(PersistenceService.java:37)
at com.bo.df.designer.domain.BaseTableTest.delete(BaseTableTest.java:89)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:71)
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.hibernate.MappingException: Unknown entity: com.bo.df.designer.domain.BaseTable
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:550)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1338)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:97)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:53)
at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:677)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:661)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:665)
at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:227)
Name and version of the database you are using:

The generated SQL (show_sql=true):
no sql generated

Debug level Hibernate log excerpt:
22:52:46,001 INFO CollectionFactory:73 - JDK 1.4+ collections available
22:52:46,064 INFO XmlBeanDefinitionReader:330 - Loading XML bean definitions from class path resource [com/bo/df/designer/dao/declarativeServices.xml]
22:52:46,720 INFO DriverManagerDataSource:155 - Loaded JDBC driver: org.hsqldb.jdbcDriver
22:52:47,595 INFO Version:15 - Hibernate EntityManager 3.2.1.GA
22:52:47,626 INFO Version:15 - Hibernate Annotations 3.2.1.GA
22:52:47,626 INFO Environment:509 - Hibernate 3.2.2
22:52:47,642 INFO Environment:542 - hibernate.properties not found
22:52:47,642 INFO Environment:676 - Bytecode provider name : cglib
22:52:47,642 INFO Environment:593 - using JDK 1.4 java.sql.Timestamp handling
22:52:47,814 INFO Ejb3Configuration:291 - Processing PersistenceUnitInfo [
name: simplep
...]
22:52:47,845 INFO Configuration:553 - Reading mappings from resource : META-INF/orm.xml
22:52:47,845 INFO Ejb3Configuration:931 - [PersistenceUnit: simplep] no META-INF/orm.xml found
22:52:47,985 INFO ConnectionProviderFactory:72 - Initializing connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
22:52:47,985 INFO InjectedDataSourceConnectionProvider:38 - Using provided datasource
22:52:48,126 INFO SettingsFactory:89 - RDBMS: HSQL Database Engine, version: 1.8.0
22:52:48,126 INFO SettingsFactory:90 - JDBC driver: HSQL Database Engine Driver, version: 1.8.0
22:52:48,157 INFO Dialect:152 - Using dialect: org.hibernate.dialect.HSQLDialect
22:52:48,251 INFO TransactionFactoryFactory:34 - Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
22:52:48,251 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
22:52:48,251 INFO SettingsFactory:143 - Automatic flush during beforeCompletion(): disabled
22:52:48,267 INFO SettingsFactory:147 - Automatic session close at end of transaction: disabled
22:52:48,267 INFO SettingsFactory:154 - JDBC batch size: 15
22:52:48,267 INFO SettingsFactory:157 - JDBC batch updates for versioned data: disabled
22:52:48,267 INFO SettingsFactory:162 - Scrollable result sets: enabled
22:52:48,267 INFO SettingsFactory:170 - JDBC3 getGeneratedKeys(): disabled
22:52:48,267 INFO SettingsFactory:178 - Connection release mode: auto
22:52:48,282 INFO SettingsFactory:205 - Default batch fetch size: 1
22:52:48,282 INFO SettingsFactory:209 - Generate SQL with comments: disabled
22:52:48,282 INFO SettingsFactory:213 - Order SQL updates by primary key: disabled
22:52:48,282 INFO SettingsFactory:382 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
22:52:48,282 INFO ASTQueryTranslatorFactory:24 - Using ASTQueryTranslatorFactory
22:52:48,282 INFO SettingsFactory:221 - Query language substitutions: {}
22:52:48,282 INFO SettingsFactory:226 - JPA-QL strict compliance: enabled
22:52:48,282 INFO SettingsFactory:231 - Second-level cache: enabled
22:52:48,282 INFO SettingsFactory:235 - Query cache: disabled
22:52:48,282 INFO SettingsFactory:369 - Cache provider: org.hibernate.cache.NoCacheProvider
22:52:48,282 INFO SettingsFactory:250 - Optimize cache for minimal puts: disabled
22:52:48,298 INFO SettingsFactory:259 - Structured second-level cache entries: disabled
22:52:48,314 INFO SettingsFactory:279 - Echoing all SQL to stdout
22:52:48,314 INFO SettingsFactory:286 - Statistics: disabled
22:52:48,314 INFO SettingsFactory:290 - Deleted entity synthetic identifier rollback: disabled
22:52:48,314 INFO SettingsFactory:305 - Default entity-mode: pojo
22:52:48,314 INFO SettingsFactory:309 - Named query checking : enabled
22:52:48,360 INFO SessionFactoryImpl:161 - building session factory
22:52:48,376 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
22:52:48,392 INFO SchemaUpdate:115 - Running hbm2ddl schema update
22:52:48,392 INFO SchemaUpdate:126 - fetching database metadata
22:52:48,392 INFO SchemaUpdate:138 - updating schema
22:52:48,392 INFO SchemaUpdate:160 - schema update complete
22:52:48,470 INFO DriverManagerDataSource:155 - Loaded JDBC driver: org.hsqldb.jdbcDriver


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 01, 2007 8:47 am 
Beginner
Beginner

Joined: Thu Jun 17, 2004 10:08 am
Posts: 21
Location: Paris-France
Well,
I found the solution; you must add the <class>my.entity.class</class> into the persistence.xml file Normally Hibernate should scan the classes and automatically find the annotated classes but id does not work :(

Cheers,
Adrian


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 07, 2007 7:20 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
if your classes are in the same jar/exploded dir as your META-INF/persistence.xml, it does work.
Note sure if inside the Spring container, I haven't tested t, but I bet they have.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: org.hibernate.MappingException: Unknown entity:
PostPosted: Wed Aug 05, 2009 3:36 pm 
Newbie

Joined: Wed Aug 05, 2009 3:27 pm
Posts: 1
Adrian, thanks a lot for the help - solved my problem.


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.