-->
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.  [ 7 posts ] 
Author Message
 Post subject: org.hibernate.MappingException: Unknown entity: main.java...
PostPosted: Mon Aug 09, 2010 3:30 am 
Newbie

Joined: Tue Jul 20, 2010 3:56 am
Posts: 6
Hello Forum,

started a new hibernate project, it should use just the annotated classes. My initial test code looks like:
Code:
package main.java.de.vaod.dao;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Entity
public class User {
    private Long id;

    @Id
    @GeneratedValue
    public Long getId() {
   return id;
    }

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

the test:
Code:
package test.java.de.vaod.backend;

import junit.framework.TestCase;

import main.java.de.vaod.dao.User;

import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.classic.Session;

public class UserTest extends TestCase {

    public void testSave() {
   SessionFactory sessionFactory = new AnnotationConfiguration()
      .configure().buildSessionFactory();
   Session session = sessionFactory.openSession();
   Transaction transaction = session.beginTransaction();

   User user = new User();
   session.save(user);

   transaction.commit();
   session.close();
   sessionFactory.close();

   assertNotNull(user.getId());
    }
}

The MappingException happen in the test in the Line new User(); the trace told me:
Code:
org.hibernate.MappingException: Unknown entity: main.java.de.vaod.dao.User
   at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:706)
   at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1475)
   at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
   at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
   at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
   at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:705)
   at org.hibernate.impl.SessionImpl.save(SessionImpl.java:693)
   at org.hibernate.impl.SessionImpl.save(SessionImpl.java:689)
   at test.java.de.vaod.backend.UserTest.testSave(UserTest.java:25)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:616)
   at junit.framework.TestCase.runTest(TestCase.java:164)
   at junit.framework.TestCase.runBare(TestCase.java:130)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:120)
   at junit.framework.TestSuite.runTest(TestSuite.java:230)
   at junit.framework.TestSuite.run(TestSuite.java:225)
   at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

I dont know what iam doing wrong. Any help will be very appreciated.

Daniel


Top
 Profile  
 
 Post subject: Re: org.hibernate.MappingException: Unknown entity: main.java...
PostPosted: Mon Aug 09, 2010 3:39 am 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
Hello Daniel,

In your annotated class, you havent mentioned the table . To which table this POJO is mapped?

Check that once.

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


Top
 Profile  
 
 Post subject: Re: org.hibernate.MappingException: Unknown entity: main.java...
PostPosted: Mon Aug 09, 2010 4:35 am 
Newbie

Joined: Tue Jul 20, 2010 3:56 am
Posts: 6
Thank you for your message, the documentation told me that
Code:
...
@Entity
@Table
public class User {
...

is sufficent, the table name is then the same like the classname (User). But problem persist. Perhaps the book iam reading about is to old...
Please give me an example so that i can understand what you mean. Thanks

Daniel


Top
 Profile  
 
 Post subject: Re: org.hibernate.MappingException: Unknown entity: main.java...
PostPosted: Mon Aug 09, 2010 5:32 am 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
In the cfg.xml file, please check once whether you have mapped this annotated class.

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


Top
 Profile  
 
 Post subject: Re: org.hibernate.MappingException: Unknown entity: main.java...
PostPosted: Mon Aug 09, 2010 6:04 am 
Newbie

Joined: Tue Jul 20, 2010 3:56 am
Posts: 6
i created a hibernate.cfg.xml only, that contains:
Code:
<?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.connection.driver_class">com.mysql.jdbc.Driver</property>
      <property name="hibernate.connection.url">jdbc:mysql://localhost/vaod</property>
      <property name="hibernate.connection.username">vaod</property>
      <property name="hibernate.connection.password"></property>
      <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
      <property name="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
      <property name="hibernate.show_sql">true</property>
      <property name="hibernate.format_sql">true</property>
      <property name="hibernate.hbm2ddl.auto">update</property>
   </session-factory>
</hibernate-configuration>

I thought was thats not required to create a mapping file because iam use annotations. I become not clued with the annotations stuff, i don't want use xml a lot. Thanks for supporting me again.


Top
 Profile  
 
 Post subject: Re: org.hibernate.MappingException: Unknown entity: main.java...
PostPosted: Mon Aug 09, 2010 6:17 am 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
Hi Drindt,

Please go through this link. I have a feeling that some thing went wrong in configuration.

http://docs.jboss.org/hibernate/stable/ ... /ch01.html

thanks.

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


Top
 Profile  
 
 Post subject: Re: org.hibernate.MappingException: Unknown entity: main.java...
PostPosted: Wed Sep 29, 2010 11:34 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.  [ 7 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.