-->
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.  [ 5 posts ] 
Author Message
 Post subject: MappingException: No persister for: java.lang.Long
PostPosted: Tue Jul 26, 2005 7:09 am 
Newbie

Joined: Mon Jul 18, 2005 6:57 am
Posts: 12
Hi,

I'm trying to do a search for some Users based on the foriegn key in my User class and I get the error:

net.sf.hibernate.MappingException: No persister for: java.lang.Long
at net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:347)
at net.sf.hibernate.impl.SessionImpl.getClassPersister(SessionImpl.java:2690)
at net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2697)
at net.sf.hibernate.impl.SessionImpl.getEntityIdentifierIfNotUnsaved(SessionImpl.java:2759)
at net.sf.hibernate.type.EntityType.getIdentifier(EntityType.java:66)
at net.sf.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:47)
at net.sf.hibernate.loader.Loader.bindPositionalParameters(Loader.java:749)
at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:788)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:265)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
at net.sf.hibernate.loader.CriteriaLoader.list(CriteriaLoader.java:118)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:3613)
at net.sf.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:238)
at uk.gov.ch.chips.server.user.UserHibernateDao.getUsersByOrgUnit(UserHibernateDao.java:238)
at uk.gov.ch.chips.server.user.UserDaoTest.testGetUsersByOrgUnitId(UserDaoTest.java:159)
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:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
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:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:474)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194)

-------------------------------------------------------------

The code where I am making the call to Hibernate from is

public List getUsersByOrgUnit(long orgUnitId) {

List users = new ArrayList();

Criteria criteria = getSession().createCriteria(User.class);
criteria.add(Expression.eq("homeOrgUnit", new Long(orgUnitId)));
criteria.add(Expression.lt("effectiveDate", DateUtils.today()));
criteria.add(Expression.gt("endDate", DateUtils.today()));

try {
users = criteria.list();
} catch (HibernateException e) {
LOG.fatal("Problem finding the Users in the database.", e);
throw new RuntimeException(
"Problem finding the Users in the database.", e);
}

return users;
}



My Mapping file is:

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class
name="uk.gov.ch.chips.common.user.User"
table="USER_ACCESS"
dynamic-update="false"
dynamic-insert="false"
>

<id name="id"
column="USER_ACCESS_ID"
type="java.lang.Long"
access="field">
<generator class="assigned" />
</id>

<property name="loginId"
column="LOGIN_ID"
type="string"
update="true"
insert="true"
access="field"
length="30"
not-null="true"
/>

<property name="firstName"
column="USER_FORENAME"
type="string"
access="field"
length="50"
/>

<property name="lastName"
column="USER_SURNAME"
type="string"
access="field"
length="160"
/>

<property name="emailAddress"
column="USER_EMAIL"
type="string"
access="field"
length="256"
/>

<property name="telExt"
column="USER_TELEPHONE_NO"
type="string"
access="field"
/>

<property
name="locked"
type="yes_no"
update="true"
insert="true"
access="property"
column="Locked_IND"
length="1"
not-null="true"
/>

<property name="loginFailureCount"
column="LOGIN_FAILURE_COUNT"
type="int"
update="true"
insert="true"
access="property"
length="4"
not-null="true"
/>

<property
name="effectiveDate"
type="java.util.Date"
access="field"
column="USER_EFF_DATE"
length="10"
not-null="true"
/>

<property
name="endDate"
type="java.util.Date"
access="field"
column="USER_END_DATE"
length="10"
not-null="true"
/>

<many-to-one name="homeOrgUnit"
class="uk.gov.ch.chips.common.user.OrgUnit"
access="field"
column ="ORGANISATIONAL_UNIT_ID"
/>

<list name="userPrivileges"
table="USER_PRIVILEGE"
lazy="true"
inverse="true"
access="field">
<key column="USER_ACCESS_ID" />
<index column="USER_PRIVILEGE_ID" />
<many-to-many class="uk.gov.ch.chips.common.user.Privilege"
column="PRIVILEGE_TYPE_ID" />
</list>

<list name="userGroups"
table="USERACC_GROUPACC_LINK"
lazy="true"
inverse="true"
access="field"
cascade="save-update">
<key column="USER_ACCESS_ID" />
<index column="USER_GROUPACC_LINK_ID" />
<many-to-many class="uk.gov.ch.chips.common.user.Group"
column="GROUP_ACCESS_ID" />
</list>

</class>

</hibernate-mapping>

The error seems to be with the <many-to-one name="homeOrgUnit

Any pointers would be very greatly appreciated.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 26, 2005 7:45 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
yes, you're quite right ... it's a "problem" how you're trying to query the many-to-one ...

Code:
criteria.add(Expression.eq("homeOrgUnit", new Long(orgUnitId)));


is not possible because Hibernate would expect an instance of "uk.gov.ch.chips.common.user.OrgUnit" and not the id ... If you want to use the id in the query, there're several possibilities.

Look at the reference-doc (or HiA) for using an "Alias" or "join" in combination with criteria ...

You can try something like this (not tested - just an example):
Code:
Criteria criteria = getSession().createCriteria(User.class);
criteria.add(Expression.lt("effectiveDate", DateUtils.today()));
criteria.add(Expression.gt("endDate", DateUtils.today()));
criteria.createAlias("homeOrgUnit", "ho");
criteria.add(Expression.eq("ho.nameOfTheIDProperty", new Long(orgUnitId)));
...


HiH
curio


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 26, 2005 7:48 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Or:

Code:
criteria.add(Expression.eq("homeOrgUnit.id", new Long(orgUnitId)));


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 26, 2005 8:11 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
@gavin
don't want to hijack this thead.... but i've tried using "object.property" in criteria and got an "net.sf.hibernate.QueryException: could not resolve property: object.property of ..." in v2.1.8 ...
Is your suggestion always working, or only for id-fields? I'm just asking that stupid, because of my above mentioned problems.
Using an alias solved it ...

thx!
curio


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 26, 2005 8:46 am 
Newbie

Joined: Mon Jul 18, 2005 6:57 am
Posts: 12
Thank you very much. Worked perfectly. Becomes so obvious when you see the example...


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