Hi everyone.
I'm a beginner, and am trying out a very simple program to understand the concepts. There's Users class, which has "username" and "pswd" columns. A UserRights table has a username column which references username in Users and a userrights column which is an integer holding a numeric value. The UserRights table also has a surrogate primary key column. I am able to retreive records from the UserRights table, but I am not able to insert any records into the UserRights table.
I keep getting a
net.sf.hibernate.MappingException: Unknown entity class: java.lang.String
error.
Any help is greatly appreciated.
Hibernate version: 2.1.7
Mapping documents:
Users.hbm.xml:
Code:
<hibernate-mapping>
<class name="okay.hbvo.Users" table="users">
<id name="username" type="java.lang.String">
<generator class="assigned"/>
</id>
<property name="pswd" type="java.lang.String"/>
</class>
</hibernate-mapping>
UserRight.hbm.xml:Code:
<hibernate-mapping>
<class name="okay.hbvo.UserRight" table="userright">
<id name="surrpk" type="java.lang.Integer" unsaved-value="0">
<generator class="increment"/>
</id>
<many-to-one name="username" class="okay.hbvo.Users" column="username" unique="true"/>
<property name="userRights" type="java.lang.Long"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
getting the DAO:
UserRightDAO urdao = DAOFactory.getUserRightDAO();
Long uright = new Long((long)12345);
String urname = new String("karan"); // this user exists in Users table
UserRight uro = new UserRight(urname, uright);
urdao.insertUR(uro);
MainUserRightDAO's insertUR function (takes a UserRight object as parameter):
HibernateUtil.beginTransaction();
Session session = HibernateUtil.getSession();
session.save(URo);
HibernateUtil.commitTransaction();
HibernateUtil.closeSession();
Full stack trace of any exception that occurs:
2004-12-26 10:57:33,548 [main] DEBUG okay.dao.HibernateUtil - ****************** SESSIONFACTORY MADE ******************
2004-12-26 10:57:33,549 [main] DEBUG okay.dao.HibernateUtil - Starting new database transaction in this thread.
2004-12-26 10:57:33,550 [main] DEBUG okay.dao.HibernateUtil - Opening new Session for this thread.
2004-12-26 10:57:33,934 [main] DEBUG net.sf.hibernate.impl.SessionImpl - opened session
2004-12-26 10:57:33,940 [main] DEBUG net.sf.hibernate.transaction.JDBCTransaction - begin
2004-12-26 10:57:33,942 [main] DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider - total checked-out connections: 0
2004-12-26 10:57:33,944 [main] DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider - using pooled JDBC connection, pool size: 0
2004-12-26 10:57:33,945 [main] DEBUG net.sf.hibernate.transaction.JDBCTransaction - current autocommit status:false
2004-12-26 10:57:33,950 [main] DEBUG net.sf.hibernate.id.IncrementGenerator - fetching initial value: select max(surrpk) from userright
2004-12-26 10:57:33,960 [main] DEBUG net.sf.hibernate.id.IncrementGenerator - first free id: 1
2004-12-26 10:57:33,962 [main] DEBUG net.sf.hibernate.impl.SessionImpl - generated identifier: 1
2004-12-26 10:57:33,967 [main] DEBUG net.sf.hibernate.impl.SessionImpl - saving [okay.hbvo.UserRight#1]
######### Exception in insertUR ############
2004-12-26 10:57:34,143 [main] DEBUG okay.dao.HibernateUtil - Tyring to rollback database transaction of this thread.
2004-12-26 10:57:34,145 [main] DEBUG net.sf.hibernate.transaction.JDBCTransaction - rollback
2004-12-26 10:57:34,147 [main] DEBUG net.sf.hibernate.impl.SessionImpl - transaction completion
2004-12-26 10:57:34,148 [main] DEBUG okay.dao.HibernateUtil - Closing Session of this thread.
2004-12-26 10:57:34,149 [main] DEBUG net.sf.hibernate.impl.SessionImpl - closing session
2004-12-26 10:57:34,150 [main] DEBUG net.sf.hibernate.impl.SessionImpl - disconnecting session
2004-12-26 10:57:34,155 [main] DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider - returning connection to pool, pool size: 1
2004-12-26 10:57:34,157 [main] DEBUG net.sf.hibernate.impl.SessionImpl - transaction completion
net.sf.hibernate.MappingException: Unknown entity class: java.lang.String
net.sf.hibernate.MappingException: Unknown entity class: java.lang.String
at net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:346)
at net.sf.hibernate.impl.SessionImpl.getClassPersister(SessionImpl.java:2694)
at net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2701)
at net.sf.hibernate.impl.SessionImpl.isUnsaved(SessionImpl.java:1092)
at net.sf.hibernate.impl.SessionImpl.nullifyTransientReferences(SessionImpl.java:1038)
at net.sf.hibernate.impl.SessionImpl.nullifyTransientReferences(SessionImpl.java:1024)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:928)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:858)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:780)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:739)
at okay.dao.MainUserRightDAO.insertUR(MainUserRightDAO.java:16)
at okay.hibMain.main(hibMain.java:23)
######### Exception in hibMAIN ############
okay.dao.InfrastructureException: net.sf.hibernate.MappingException: Unknown entity class: java.lang.String
okay.dao.InfrastructureException: net.sf.hibernate.MappingException: Unknown entity class: java.lang.String
at okay.dao.MainUserRightDAO.insertUR(MainUserRightDAO.java:27)
at okay.hibMain.main(hibMain.java:23)
Caused by: net.sf.hibernate.MappingException: Unknown entity class: java.lang.String
at net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:346)
at net.sf.hibernate.impl.SessionImpl.getClassPersister(SessionImpl.java:2694)
at net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2701)
at net.sf.hibernate.impl.SessionImpl.isUnsaved(SessionImpl.java:1092)
at net.sf.hibernate.impl.SessionImpl.nullifyTransientReferences(SessionImpl.java:1038)
at net.sf.hibernate.impl.SessionImpl.nullifyTransientReferences(SessionImpl.java:1024)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:928)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:858)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:780)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:739)
at okay.dao.MainUserRightDAO.insertUR(MainUserRightDAO.java:16)
... 1 more
Name and version of the database you are using:
PostgreSQL 7.4.2
The generated SQL (show_sql=true):
2004-12-26 10:57:33,950 [main] DEBUG net.sf.hibernate.id.IncrementGenerator - fetching initial value: select max(surrpk) from userright
This is all I see.
Debug level Hibernate log excerpt:
its up there.