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.xmlmy 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 isCode:
<?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>
<property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
<mapping resource="tyn/cm/hibernate/UserAccount.hbm.xml" />
</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