-->
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: ClassCastException bei session.refresh(...)
PostPosted: Sun Jun 11, 2006 6:50 am 
Regular
Regular

Joined: Thu Jun 08, 2006 5:32 pm
Posts: 52
Hibernate version: 3

Einführung:
3 Klassen: VOKunde, VOZimmer, VOReservierung; eine Reservierung bezieht sich auf genau ein Zimmer und einen Kunden. Damit die Reservierungs-Klasse den in der Datenbank generierten Timestamp bekommt mach ich beim speichern folgendes:

Hinweis: vor jedem Zugriff ruf ich beginTransaction() und nach jedem Zugriff endTransaction(boolean erfolgreichOderNicht).

Code:
public void beginTransaction(){
   try {
      this.sessionFactory = new Configuration().configure().buildSessionFactory();
      this.session = this.sessionFactory.openSession();
      this.transaction = this.session.beginTransaction();
   }
   catch (HibernateException hibernateExc) {
      throw new Failure("beginTransaction() failure", hibernateExc);
   }
         
}

//-------------------------------------------------------------------------

public void speichern(final VOObject i_daten) {
   try {
      this.session.save(i_daten);
      this.session.flush();
      this.session.refresh(i_daten);
   }
   catch (HibernateException hibernateExc) {
      throw new Failure("speichern(...) failure", hibernateExc);
   }
}

//-------------------------------------------------------------------------

public void endTransaction(final boolean i_ok){
   try {
      if(i_ok==true){
         this.transaction.commit();
         this.session.flush();
      }
      else this.transaction.rollback();

      this.session.close();
   }
   catch(HibernateException hibernateExc){
      throw new Failure("endTransaction({0}) failure", hibernateExc, new Boolean(i_ok));
   }
}


nun kommt (nur beim speichern der VOReservierung (nicht bei VOKunde oder VOZimmer)) die unten gepostete ClassCastException. Wenn ich das refresh rausnehme geht es, aber dann bekommen die gespeicherten Objekte ja leider nicht den Timestamp.

Nun habe ich folgendes Problem:

Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
   
<hibernate-mapping>
   <class name="lg.vo.VOReservierung" table="VOReservierung">
      <id name="oid" type="int" column="OID" >
          <generator class="increment"/>
       </id>
   
       <many-to-one name="kunde" column="ID_KUNDE" class="lg.vo.VOKunde"/>
   
       <many-to-one name="zimmer" column="ID_ZIMMER" class="lg.vo.VOZimmer"/>
        
         <property name="nummer">
            <column name="NUMMER"/>
         </property>
      
         <property name="von">
            <column name="VON"/>
         </property>
      
         <property name="bis">
            <column name="BIS"/>
         </property>
         
         <property name="anreise">
            <column name="ANREISE"/>
         </property>
         
         <property name="abreiseOderStorniert">
            <column name="ABREISE_ODER_STORNIERT"/>
         </property>
         
         <property name="rechnungsDatum">
            <column name="RECHNUNGSDATUM"/>
         </property>
      
         <property name="rechnungsSummeInCent">
            <column name="RECHNUNGSSUMME_IN_CENT"/>
         </property>
         
         <property name="zeitstempel">
         <column name="ZEITSTEMPEL" />
      </property>
      
         <set name="zusatzleistung" table="vozusatzleistung">
            <key column="reservierung_oid"/>
            <one-to-many class="lg.vo.VOZusatzleistung"/>
      </set>
   </class>
</hibernate-mapping>


Full stack trace of any exception that occurs:
Exception in thread "main" java.lang.ClassCastException: org.hibernate.collection.PersistentSet
WAS CAUSING:
net.sf.cglib.beans.BulkBeanException: org.hibernate.collection.PersistentSet
at lg.vo.VOReservierung$$BulkBeanByCGLIB$$ce7000a4.setPropertyValues(<generated>)
at org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:194)
WAS CAUSING:
org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of lg.vo.VOReservierung.setZusatzleistung
at org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:197)
at org.hibernate.tuple.PojoTuplizer.setPropertyValues(PojoTuplizer.java:167)
at org.hibernate.persister.entity.BasicEntityPersister.setPropertyValues(BasicEntityPersister.java:2879)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:452)
at org.hibernate.loader.Loader.doQuery(Loader.java:406)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:203)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1255)
at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:139)
at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:124)
at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2453)
at org.hibernate.event.def.DefaultRefreshEventListener.onRefresh(DefaultRefreshEventListener.java:94)
at org.hibernate.impl.SessionImpl.refresh(SessionImpl.java:618)
at db.DbSitzung.speichern(DbSitzung.java:113)
WAS CAUSING:
multex.Failure: speichern(...) failure
at db.DbSitzung.speichern(DbSitzung.java:116)
at lg.LgSitzung.reservierungAnlegen(LgSitzung.java:282)
at lg.Test.main(Test.java:26)


Top
 Profile  
 
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.