-->
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.  [ 11 posts ] 
Author Message
 Post subject: "MappingException: Unknown entity" : help needed
PostPosted: Tue Aug 22, 2006 6:05 am 
Newbie

Joined: Tue Aug 22, 2006 5:26 am
Posts: 10
Location: Pakistan
Need help with Hibernate? got exception
org.hibernate.MappingException: Unknown entity tyn.cm.hibernate.UserAccount

Full stack trace of any exception that occurs:

Code:
14:19:57,031 ERROR [STDERR] org.hibernate.MappingException: Unknown entity: tyn.cm.hibernate.UserAccount
        at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:547)
        at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1331)
        at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:96)
        at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventL
istener.java:186)
        at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)

        at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:
175)
        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:537)
        at org.hibernate.impl.SessionImpl.save(SessionImpl.java:525)
        at org.hibernate.impl.SessionImpl.save(SessionImpl.java:521)
        at tyn.cm.pagebean.SignupPageBean.insertUserAccountInfo(SignupPageBean.java:71)
        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.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:129)
        at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)
        at javax.faces.component.UICommand.broadcast(UICommand.java:106)
        at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:90)
        at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:164)
        at org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:316)
        at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:86)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:106)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664
)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
        at java.lang.Thread.run(Thread.java:595)

Hibernate version:

Mapping documents: UserAccount.hbm.xml
my mapping file and UserAccount class is in same package tyn.cm.hibernate

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">
<!-- Generated Aug 22, 2006 11:58:57 AM by Hibernate Tools 3.1.0.beta5 -->
<hibernate-mapping>
    <class name="tyn.cm.hibernate.UserAccount" table="userAccount" schema="dbo" catalog="YellowNumber">
        <id name="userId" type="string">
            <column name="userID" length="36" />
            <generator class="assigned" />
        </id>
        <property name="businessId" type="string">
            <column name="businessID" length="36" />
        </property>
        <property name="userName" type="string">
            <column name="userName" length="36" />
        </property>
        <property name="password" type="string">
            <column name="password" length="50" />
        </property>
        <property name="firstName" type="string">
            <column name="firstName" length="50" not-null="true" />
        </property>
        <property name="lastName" type="string">
            <column name="lastName" length="50" not-null="true" />
        </property>
        <property name="securityQuestion" type="string">
            <column name="securityQuestion" length="50" />
        </property>
        <property name="answer" type="string">
            <column name="answer" length="50" />
        </property>
        <property name="emailAddress" type="string">
            <column name="emailAddress" length="50" not-null="true" />
        </property>
        <property name="status" type="byte">
            <column name="status" not-null="true" />
        </property>
        <property name="locale" type="string">
            <column name="locale" length="5" />
        </property>
        <property name="userRole" type="string">
            <column name="userRole" length="50" />
        </property>
        <property name="createDate" type="timestamp">
            <column name="createDate" length="23" not-null="true" />
        </property>
    </class>
</hibernate-mapping>

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

Code:
Transaction tx = session.beginTransaction();
         /* Create new instance and set values in it by reading them form object*/
         UserAccount userAccount = new UserAccount();
         userAccount.setFirstName(this.userBean.getFirstName());
         System.out.println("going to save");
         session.save(userAccount);
         tx.commit();
         session.flush();
         str = "greeting";
         session.close();
         sessionFactory.close();


Name and version of the database you are using:
SQLServer 2000

The generated SQL (show_sql=true):
Code:
14:19:57,031 WARN  [JDBCExceptionReporter] SQL Warning: 0, SQLState:
14:19:57,031 WARN  [JDBCExceptionReporter] [Microsoft][SQLServer 2000 Driver for JDBC]Database changed to YellowNumber
14:19:57,031 WARN  [JDBCExceptionReporter] SQL Warning: 0, SQLState:
14:19:57,031 WARN  [JDBCExceptionReporter] [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Changed database context to
'YellowNumber'.
14:19:57,031 WARN  [JDBCExceptionReporter] SQL Warning: 0, SQLState:
14:19:57,031 WARN  [JDBCExceptionReporter] [Microsoft][SQLServer 2000 Driver for JDBC]Language changed to us_english
14:19:57,031 WARN  [JDBCExceptionReporter] SQL Warning: 0, SQLState:
14:19:57,031 WARN  [JDBCExceptionReporter] [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Changed language setting to
us_english.
14:19:57,046 INFO  [SessionFactoryImpl] closing
14:19:57,046 INFO  [DriverManagerConnectionProvider] cleaning up connection pool: jdbc:microsoft:sqlserver://kashif:1433;Dat
abaseName=YellowNumber;SelectMethod=cursor
14:22:12,468 INFO  [DriverManagerConnectionProvider] cleaning up connection pool: jdbc:microsoft:sqlserver://kashif:1433;Dat
abaseName=YellowNumber;SelectMethod=cursor

Debug level Hibernate log excerpt:

Code:
14:19:56,984 INFO  [Configuration] configuring from resource: /hibernate.cfg.xml
14:19:56,984 INFO  [Configuration] Configuration resource: /hibernate.cfg.xml
14:19:57,000 INFO  [Configuration] Configured SessionFactory: null
14:19:57,000 INFO  [DriverManagerConnectionProvider] Using Hibernate built-in connection pool (not for production use!)
14:19:57,000 INFO  [DriverManagerConnectionProvider] Hibernate connection pool size: 20
14:19:57,000 INFO  [DriverManagerConnectionProvider] autocommit mode: false
14:19:57,000 INFO  [DriverManagerConnectionProvider] using driver: com.microsoft.jdbc.sqlserver.SQLServerDriver at URL: jdbc
:microsoft:sqlserver://kashif:1433;DatabaseName=YellowNumber;SelectMethod=cursor
14:19:57,000 INFO  [DriverManagerConnectionProvider] connection properties: {user=tyn, password=tyn}
14:19:57,015 INFO  [SettingsFactory] RDBMS: Microsoft SQL Server, version: Microsoft SQL Server  2000 - 8.00.194 (Intel X86)

        Aug  6 2000 00:57:48
        Copyright (c) 1988-2000 Microsoft Corporation
        Personal Edition on Windows NT 5.1 (Build 2600: Service Pack 1)

14:19:57,015 INFO  [SettingsFactory] JDBC driver: SQLServer, version: 2.2.0029
14:19:57,015 INFO  [Dialect] Using dialect: org.hibernate.dialect.SQLServerDialect
14:19:57,015 INFO  [TransactionFactoryFactory] Using default transaction strategy (direct JDBC transactions)
14:19:57,015 INFO  [TransactionManagerLookupFactory] No TransactionManagerLookup configured (in JTA environment, use of read
-write or transactional second-level cache is not recommended)
14:19:57,015 INFO  [SettingsFactory] Automatic flush during beforeCompletion(): disabled
14:19:57,015 INFO  [SettingsFactory] Automatic session close at end of transaction: disabled
14:19:57,015 INFO  [SettingsFactory] Scrollable result sets: enabled
14:19:57,015 INFO  [SettingsFactory] JDBC3 getGeneratedKeys(): disabled
14:19:57,015 INFO  [SettingsFactory] Connection release mode: auto
14:19:57,015 INFO  [SettingsFactory] Default batch fetch size: 1
14:19:57,015 INFO  [SettingsFactory] Generate SQL with comments: disabled
14:19:57,015 INFO  [SettingsFactory] Order SQL updates by primary key: disabled
14:19:57,015 INFO  [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
14:19:57,015 INFO  [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
14:19:57,015 INFO  [SettingsFactory] Query language substitutions: {}
14:19:57,015 INFO  [SettingsFactory] Second-level cache: enabled
14:19:57,015 INFO  [SettingsFactory] Query cache: disabled
14:19:57,015 INFO  [SettingsFactory] Cache provider: org.hibernate.cache.EhCacheProvider
14:19:57,015 INFO  [SettingsFactory] Optimize cache for minimal puts: disabled
14:19:57,015 INFO  [SettingsFactory] Structured second-level cache entries: disabled
14:19:57,015 INFO  [SettingsFactory] Statistics: disabled
14:19:57,015 INFO  [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
14:19:57,015 INFO  [SettingsFactory] Default entity-mode: pojo
14:19:57,015 INFO  [SessionFactoryImpl] building session factory
14:19:57,031 WARN  [ConfigurationFactory] No configuration found. Configuring ehcache from ehcache-failsafe.xml  found in th
e classpath: jar:file:/E:/Development/jboss-4.0.4.GA/server/default/lib/ehcache-1.2.jar!/ehcache-failsafe.xml
14:19:57,031 INFO  [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
14:19:57,031 INFO  [STDOUT] got session from sessionFactory
14:19:57,031 INFO  [STDOUT] going to save


my cfg file is
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.microsoft.jdbc.sqlserver.SQLServerDriver</property>
        <property name="hibernate.connection.password">tyn</property>
        <property name="hibernate.connection.url">jdbc:microsoft:sqlserver://kashif:1433;DatabaseName=YellowNumber;SelectMethod=cursor</property>
        <property name="hibernate.connection.username">tyn</property>
        <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
    </session-factory>
</hibernate-configuration>


I successfuly done console configuration, in which I connect to database select my table and generat classes UserAccount and UserAccountHome with UserAccount.hbm.xml. I also uses revenge xml by doing mapping by selecting my table. And in cosole configuration I have also added my bin output folder in classpath. Also added mapping document from console configuration.

I m looking for corrections that what thing(s) I m missing or what corrections I require. Please review my code snippets and reply

Thx

_________________
Tahir


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 22, 2006 11:28 am 
Newbie

Joined: Tue Aug 22, 2006 11:25 am
Posts: 2
I think you have created object for transaction tx, so try to save with the transaction.

tx.save(userAccount); instead of session.save

_________________
Regards,

Suresh


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 22, 2006 11:50 am 
Newbie

Joined: Tue Aug 22, 2006 11:25 am
Posts: 2
I am sorry that is not the solution

_________________
Regards,

Suresh


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 22, 2006 12:29 pm 
Newbie

Joined: Thu May 04, 2006 5:04 am
Posts: 17
Location: Austria
Are you sure that your Hibernate Mapping File is accessible during runtime?
If you are using the Spring Framework check if your Hibernate Mapping File is added to the XML Configuration for the Hibernate Beans (SessionFactory). You can for example add the files one for one or add a directory which will be looked up for Hibernate Mappings.

_________________
Please don't forget to rate the posting if it helped you, thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 22, 2006 12:35 pm 
Newbie

Joined: Thu May 04, 2006 5:04 am
Posts: 17
Location: Austria
Here is an example xml configuration, look at the last 2 lines, you have to add the hbm.xml files using an "mapping resource" element.

<hibernate-configuration>

<!-- a SessionFactory instance listed as /jndi/name -->
<session-factory
name="java:comp/env/hibernate/SessionFactory">

<!-- properties -->
<property name="connection.datasource">my/first/datasource</property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">false</property>
<property name="use_outer_join">true</property>
<property name="transaction.factory_class">
net.sf.hibernate.transaction.JTATransactionFactory
</property>
<property name="jta.UserTransaction">java:comp/UserTransaction</property>

<!-- mapping files -->
<mapping resource="org/hibernate/auction/Item.hbm.xml"/>
<mapping resource="org/hibernate/auction/Bid.hbm.xml"/>

_________________
Please don't forget to rate the posting if it helped you, thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 23, 2006 12:49 am 
Newbie

Joined: Tue Aug 22, 2006 5:26 am
Posts: 10
Location: Pakistan
Dear ChristianS

I forget to mention in my code, I have already included my mapping resource file (infact only one).

I also want to ask if while in Configuration Console when I double click on the Session Factory node it give me the exception of "Unexected end of subtree", well whn I expand it, it wrks fine to show my selected table.

so can my this "entity not found" exception caused by this issue??

looking for ur valueable replyies....

_________________
Tahir


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 23, 2006 5:54 am 
Newbie

Joined: Thu May 04, 2006 5:04 am
Posts: 17
Location: Austria
Where do you add the mapping file (at runtime or is it in the hibernate cfg xml or somewhere else)?
I can't find the mapping in your posted hibernate cfg xml.
BTW, I don't know the Configuration Console you mentioned. It should work if you add the appropriate mapping in your hibernate cfg xml.

kind regards, Chris

_________________
Please don't forget to rate the posting if it helped you, thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 23, 2006 8:54 am 
Newbie

Joined: Tue Aug 22, 2006 5:26 am
Posts: 10
Location: Pakistan
dear ChristianS
very thanx for ur considerations
well I m including my m apping resource
<mapping resource="tyn/cm/hibernate/UserAccount.hbm.xml">
in my cfg xml file. My question is where should be it packaged, whether in WEB-INF or with the same directory as *Home.class

any idea

regards

_________________
Tahir


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 23, 2006 10:11 am 
Newbie

Joined: Thu May 04, 2006 5:04 am
Posts: 17
Location: Austria
In our application the hbm files are located in the same package as the Java source file for the class (ensure that they are available for the Classloader).

1. If you are creating a jar file for deployment of your application, check if the hbm file is in the folder where your UserAccount class is (use unzip to expand the jar file).

2. Have you already tried to load the hbm file by yourself using something like
Code:
InputStream hbm = getClass().getResourceAsStream("tyn/cm/hibernate/UserAccount.hbm.xml");

as a test to check if they file is accessible by the ClassLoader?

If it is missing just add it to the jar file manually as a quick and dirty workaround (check your build process later).

kind regards, Chris

_________________
Please don't forget to rate the posting if it helped you, thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 23, 2006 10:18 am 
Newbie

Joined: Tue Aug 22, 2006 5:26 am
Posts: 10
Location: Pakistan
Dear ChristianS

Well the problem has been solved, the issue was I was not packaging the right cfg xml file in the right place,

Thank u very much for the time u spare

Yes U GOT CREDIT ;0)

cheers

_________________
Tahir


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 23, 2006 10:20 am 
Newbie

Joined: Thu May 04, 2006 5:04 am
Posts: 17
Location: Austria
glad that I could help, already spent some quality time with Hibernate myself :)

_________________
Please don't forget to rate the posting if it helped you, thanks


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