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.  [ 1 post ] 
Author Message
 Post subject: hibernate set-based association error(I'm tyro)
PostPosted: Fri Jan 26, 2007 12:42 pm 

Joined: Tue Dec 12, 2006 11:50 pm
Posts: 10
I'm,Use MyEclipse/headache

//configure Person
<set name="epzongs" inverse="true" table="Epzong">
<column name="pid" not-null="true" />
<!-- -->
<one-to-many class="com.hibernate.db.Epzong" />
//Person by Set
private Set epzongs = new HashSet(0);
private Long createPerson(String fname,String lname,Integer age){
Session s=HibernateSessionFactory.getSession();
Transaction t=s.beginTransaction();
Personperson=new Person();
return person.getId();

//preparative action
private void addPersonToEvent(Long personId, Long eventId) {

Session s=HibernateSessionFactory.getSession();
Transaction t=s.beginTransaction();

Person aPerson = (Perone) s
.createQuery("select p from Perone p left join fetch p.epzongs where p.id = :pid").setParameter("pid", personId).uniqueResult();
Event anEvent = (Event) s.load(Event.class, eventId);
Session session2 = HibernateSessionFactory.getSession();
Transaction t1=s.beginTransaction();
Long eventId = mh.createEvent("My Event", new Date());
Long personId = mh.createPerson("111", "Bar",21);
mh.addPersonToEvent(personId, eventId);
System.out.println("Added person " + personId + " to event " + eventId);

Exception in thread "main" java.lang.ClassCastException: com.hibernate.db.Event$$EnhancerByCGLIB$$6abb194d
at org.hibernate.type.EntityType.toLoggableString(EntityType.java:154)
at org.hibernate.type.CollectionType.toLoggableString(CollectionType.java:146)
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:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.hibernate.bs.ManagerHibernate.addPersonToEvent(ManagerHibernate.java:84)
at com.hibernate.bs.ManagerHibernate.main(ManagerHibernate.java:97)

..//epzong table mapping
<class name="com.hibernate.db.Epzong" table="epzong" schema="dbo" catalog="hibernateDB">
<composite-id name="id" class="com.hibernate.db.EpzongId">
<key-property name="eid" type="java.lang.Long">
<column name="eid" />
<key-property name="pid" type="java.lang.Long">
<column name="pid" />
<many-to-one name="perone" class="com.hibernate.db.Perone" update="false" insert="false" fetch="select">
<column name="pid" not-null="true" />
<many-to-one name="event" class="com.hibernate.db.Event" update="false" insert="false" fetch="select">
<column name="eid" not-null="true" />


Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.