-->
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.  [ 3 posts ] 
Author Message
 Post subject: ClassCastException when the generator is native
PostPosted: Sat Dec 29, 2007 10:07 am 
Newbie

Joined: Sat Dec 29, 2007 9:58 am
Posts: 5
Hi,

new to Hibernate. just started exploring. iam having the problems with my first example.

Version: Hibernate 3
Database: Oracle 10g

Emp.cfg.xml:

<class name="Emp" table="EMP">
<meta attribute="sync-DAO">false</meta>
<id name="empno" type="int" column="EMPNO">
<generator class="native">
</generator>
</id>

application code:

Session session = HibernateHelper.getSessionFactory()
.getCurrentSession();
session.beginTransaction();

Emp emp = new Emp();

emp.setEname("A");
emp.setJob("Manager");
emp.setMgr(1000);
emp.setHiredate(new java.util.Date());
emp.setSal(12345.67);
emp.setComm(123.45);
emp.setDeptno(10);

// emp.setEmpno(1000);

session.save(emp);

session.getTransaction().commit();


iam getting the following exception.

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Hibernate: select hibernate_sequence.nextval from dual
Exception in thread "main" java.lang.ClassCastException: java.lang.Integer
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)
at events.Main.createAndStoreEmployee(Main.java:32)
at events.Main.main(Main.java:9)


Can someone help on this?

Thanks,
Raj


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 29, 2007 10:52 am 
Newbie

Joined: Sat Oct 28, 2006 3:05 pm
Posts: 10
Native identity generator returns values of type Long, so just change the type mapping to be:

<id name="empno" type="long" column="EMPNO">
<generator class="native">
</generator>


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 29, 2007 11:17 am 
Newbie

Joined: Sat Dec 29, 2007 9:58 am
Posts: 5
Still getting the same problem.

<class name="Emp" table="EMP">
<meta attribute="sync-DAO">false</meta>
<id name="empno" type="long" column="EMPNO">
<generator class="native">
<!-- <param name="sequence">emp_sequence</param> -->
</generator>
</id>


Thanks,
Raj


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