-->
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.  [ 4 posts ] 
Author Message
 Post subject: Simple issue: hibernateTemplate.get doesnt work with String?
PostPosted: Thu Aug 07, 2008 3:45 pm 
Newbie

Joined: Thu Aug 07, 2008 3:41 pm
Posts: 14
Hi,

I have a table that consists only of one column of type string.
The primary key is also that column:

The table is called DURATION_TYPE, and the column is called "TYPE".

Code:
<hibernate-mapping>
   <class name="nl.digirap.model.registration.DurationType" table="DURATION_TYPE" lazy="false">
      <id name="type" type="string" column="TYPE"/>
   </class>
</hibernate-mapping>


I get this error:

Code:
[#|2008-08-07T21:39:08.273+0200|SEVERE|sun-appserver9.1|javax.enterprise.system.container.web|_ThreadID=16;_ThreadName=httpSSLWorkerThread-8080-1;_RequestID=9c7eab0d-1f3e-4b16-be39-967fa1f7dd50;|StandardWrapperValve[DigiRap]: PWC1406: Servlet.service() for servlet DigiRap threw exception
org.hibernate.TypeMismatchException: Provided id of the wrong type. Expected: class java.lang.Integer, got class java.lang.String
        at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:86)



What am I missing here?
Does an id need to be integer?

Code:
public DurationType findDurationType(String type) {
      return (DurationType) getHibernateTemplate().get(Cyclus.class,
            type);
   }


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 07, 2008 4:02 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Maybe I am missing something, but shouldn't you have DurationType.class instead of Cyclus.class in the call to getHibernateTemplate().get()? Eg.

Code:
return (DurationType)getHibernateTemplate().get(DurationType.class, type);


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 07, 2008 4:09 pm 
Regular
Regular

Joined: Mon Jan 22, 2007 10:32 am
Posts: 101
Is the mapping posted by you complete? As far as I know, id are not required to be integer but as per the following bug, you can get this exception while loading some associated entity too.

http://opensource.atlassian.com/project ... e/HHH-3247

_________________
Please rate this post if you find it helpful


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 08, 2008 2:01 am 
Newbie

Joined: Thu Aug 07, 2008 3:41 pm
Posts: 14
nordborg wrote:
Maybe I am missing something, but shouldn't you have DurationType.class instead of Cyclus.class in the call to getHibernateTemplate().get()? Eg.

Code:
return (DurationType)getHibernateTemplate().get(DurationType.class, type);


Thanks, that fixed it!


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