-->
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.  [ 7 posts ] 
Author Message
 Post subject: object doesn't get loaded!
PostPosted: Mon Aug 28, 2006 3:17 am 
Regular
Regular

Joined: Mon Mar 06, 2006 6:18 am
Posts: 95
Location: Bern, Switzerland
Hibernate version: 3.2CR2, Hibernate Annotations 3.2CR1 (and Spring as well)

Hi all

i have a problem while loading an object. These are my mapping files /annotated classes (the important parts):

Aktion.java
Code:
@Entity
@Table(name = "TAKTION")
public class Aktion implements java.io.Serializable {

   // Fields

   private Set<TransaktionAktionMapping> transaktionsMapping = new HashSet<TransaktionAktionMapping>(
         0);

   //more FIELDS

   /**
    * @return
    */
   @OneToMany(cascade = { CascadeType.REMOVE }, fetch = FetchType.EAGER, mappedBy = "aktion")
   @Cascade( { org.hibernate.annotations.CascadeType.DELETE })
   public Set<TransaktionAktionMapping> getTransaktionsMapping() {
      return this.transaktionsMapping;
   }

   /**
    * @param transaktionsMapping
    */
   public void setTransaktionsMapping(Set<TransaktionAktionMapping> transaktionsMapping) {
      this.transaktionsMapping = transaktionsMapping;
   }
//MORE METHODS
}


Transaktion.java

/
Code:
**
* Transaktion generated by hbm2java
*/
@Entity
@Table(name = "TTRANSAKTION")
public class Transaktion implements java.io.Serializable {


   private Set<TransaktionAktionMapping> aktionsMapping = new HashSet<TransaktionAktionMapping>(0);

//MORE FIELDS


   /**
    * @return aktionsMapping
    */
   @OneToMany(cascade = { CascadeType.REMOVE}, fetch = FetchType.LAZY, mappedBy = "transaktion")
   @Cascade( { org.hibernate.annotations.CascadeType.DELETE })
   public Set<TransaktionAktionMapping> getAktionsMapping() {
      return this.aktionsMapping;
   }

   /**
    * @param aktionsMapping
    */
   public void setAktionsMapping(Set<TransaktionAktionMapping> aktionsMapping) {
      this.aktionsMapping = aktionsMapping;
   }
//MORE METHODS
}


TransaktionAktion.hbm.xml

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">
<!-- Generated 06.06.2006 09:50:36 by Hibernate Tools 3.1.0.beta5 for NDBJS Re7 -->
<hibernate-mapping>
    <class name="najsre7.model.TransaktionAktionMapping" table="TTRANSAKTION_AKTION" >
        <composite-id>
            <meta attribute="use-in-tostring">true</meta>
            <meta attribute="use-in-equals">true</meta>
         <key-many-to-one name="transaktion" class="najsre7.model.Transaktion" column="FK_TTRANSAKTION_ILAUFNR" />
         <key-many-to-one name="aktion" class="najsre7.model.Aktion" column="FK_TAKTION_ILAUFNR" />       
        </composite-id>
        <timestamp name="mutDatum" column="DMUTDAT" />
        <property name="mutUser" type="java.lang.String">
            <meta attribute="use-in-tostring">true</meta>
            <meta attribute="use-in-equals">true</meta>
            <column name="SMUTUSER" length="10" not-null="true" />
        </property>
        <property name="stvUser" type="java.lang.String">
            <meta attribute="use-in-tostring">true</meta>
            <meta attribute="use-in-equals">true</meta>
            <column name="SSTVUSER" length="10" />
        </property>
       <many-to-one name="transaktion" class="najsre7.model.Transaktion" column="FK_TTRANSAKTION_ILAUFNR" lazy="false" fetch="join" insert="false" update="false"/>
       <many-to-one name="aktion" class="najsre7.model.Aktion" column="FK_TAKTION_ILAUFNR" lazy="false" fetch="join" insert="false" update="false"/>
    </class>
</hibernate-mapping>


So i'm loading an Aktion object now, then i change the assigned TransaktionAktionMapping collection (adding or removing object) and afterwads i try to load the object again by calling the Manager Method:
Code:
Aktion aktion = securityManager.getAktion(aktionId);


But as I can see hibernate doesn't execute a SELECT statement, so my object with the new assigned collection isn't loaded.

Does somebody have an idea about this problem?

Kind Regards
Angela


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 29, 2006 5:21 am 
Regular
Regular

Joined: Mon Mar 06, 2006 6:18 am
Posts: 95
Location: Bern, Switzerland
no ideas?

angela


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 29, 2006 8:44 am 
Regular
Regular

Joined: Fri May 12, 2006 4:05 am
Posts: 106
Hi angela,

I haven't found a single hibernate-session-object in your posted code - and I think the session-handling is the key to understanding your problem.

Just one hint based on a wild guess: hibernate won't issue another select when retrieving an object that has already been loaded in the current session, it will just satisfy the request from it's session-level-cache.

Greets

piet


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 06, 2006 6:07 am 
Regular
Regular

Joined: Mon Mar 06, 2006 6:18 am
Posts: 95
Location: Bern, Switzerland
hi all

i still have the same problem :-( i habe a kurs entity which has a set of trainings attached.
if i edit the kurs i first get the kurs object with hibernate:

Code:
KursNutzergruppe1 kursNG1 = (KursNutzergruppe1) kursManager.getKursById(kursId);


//method in my KursDAOHibernate class:

Code:
public Kurs getKursById(final Integer id) {
      if (id == null) {
         throw new NullPointerException("Id cannot be null.");
      }
      return (Kurs) getObject(Kurs.class, id);
   }
public Object getObject(Class clazz, Serializable id) {
      Object o = getHibernateTemplate().get(clazz, id);

      return o;
   }


then i do some modification to the trainings attached to the kurs (adding/removing), if the validation of the trainings fails i want to reload my site with the orginial kurs object and the orgiginal trainings set attached to it...so i get the object again with the code above.

but then hibernate doesn't execute a select query.

any help appreciated

regards
angela


Top
 Profile  
 
 Post subject: Evict or refresh
PostPosted: Fri Oct 06, 2006 7:22 am 
Newbie

Joined: Wed Dec 15, 2004 1:58 pm
Posts: 16
Location: Prague, Czech Republic
Call session.evict(object) to remove object from session cache and then load it again.

Or call session.refresh(object) and you must have cascade="refresh" in your mapping.

Or you can map the other and of association inverse (not the set) and modify the set directly.


Top
 Profile  
 
 Post subject: Re: Evict or refresh
PostPosted: Fri Oct 06, 2006 7:37 am 
Regular
Regular

Joined: Mon Mar 06, 2006 6:18 am
Posts: 95
Location: Bern, Switzerland
look_as wrote:
Call session.evict(object) to remove object from session cache and then load it again.

Or call session.refresh(object) and you must have cascade="refresh" in your mapping.

Or you can map the other and of association inverse (not the set) and modify the set directly.


i tried it like that and it's working:

Code:
public Kurs getKursById(final Integer id) {
      if (id == null) {
         throw new NullPointerException("Id cannot be null.");
      }
      getSession().evict(getObject(Kurs.class, id));
      return (Kurs) getObject(Kurs.class, id);
   }


Isn't there a general way to tell hibernate to execute a session.evict? Do i have to call it in every method?

thanks a lot & regards
Angela


Top
 Profile  
 
 Post subject: One session per request
PostPosted: Fri Oct 06, 2006 11:07 am 
Newbie

Joined: Wed Dec 15, 2004 1:58 pm
Posts: 16
Location: Prague, Czech Republic
Session is light weight object and it is recommended practice to use new session each request.


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