-->
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.  [ 2 posts ] 
Author Message
 Post subject: Classcast exception: java.lang.Long
PostPosted: Thu Mar 19, 2009 6:42 am 
Newbie

Joined: Thu Mar 19, 2009 6:28 am
Posts: 3
Hi,

I am getting the following exception, when I am trying to persist a record into db. I have searched for this error in the forums, but I did not get the solution for it.

The same is working for SELECT queries :).

I am trying my luck with my thread :)

Caused by: java.lang.ClassCastException: java.lang.Long
at org.hibernate.type.StringType.toString(StringType.java:44)
at org.hibernate.type.NullableType.toLoggableString(NullableType.java:218)
at org.hibernate.pretty.Printer.toString(Printer.java:53)
at org.hibernate.pretty.Printer.toString(Printer.java:90)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:97)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)


Please help me in resolving this.


Hibernate version:3.3

Mapping documents:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="com.hma.cds.portlets.medreconc.hibernate">
<class
name="MedReconcInpatient"
table="MED_RECONC_INPATIENT"
>
<meta attribute="sync-DAO">false</meta>
<id
name="id"
type="long"
column="ID"
>
<generator class="increment"/>
</id>

<property
name="patient"
column="PATIENT"
type="string"
not-null="true"
length="50"
/>
<property
name="allergy"
column="ALLERGY"
type="string"
not-null="true"
length="40"
/>



Code between sessionFactory.openSession() and session.close():
MedReconcInpatient ipObj = new MedReconcInpatient();
ipObj.setPatient((String)obj);
ipObj.setAllergy(allergy);
ipObj.setDose(dose);
ipObj.setFlag("I");
ipObj.setFreq(freq);
ipObj.setHomeid(Long.parseLong(id));
ipObj.setIndication(indication);
ipObj.setMedication(medication);
ipObj.setRoute(route);

session.save(ipObj);



Full stack trace of any exception that occurs:

Name and version of the database you are using: Oracle 10g

The generated SQL (show_sql=true):
Hibernate: select max(ID) from MED_RECONC_INPATIENT


Debug level Hibernate log excerpt:


Thanks in advance.

Sri


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 19, 2009 9:38 am 
Beginner
Beginner

Joined: Wed Oct 03, 2007 4:10 am
Posts: 46
Please put

<id name="id" type="java.lang.Long" column="ID">
<generator class="increment"/>
</id>


and

map the 'homeId' also to 'java.lang.Long'


and try again

ps
work only with classes(Long, Integer, etc) and not with primitives(long, int, etc)


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