-->
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: I have a problema with lazy=true
PostPosted: Thu Sep 17, 2009 9:40 am 
Newbie

Joined: Thu Sep 17, 2009 8:27 am
Posts: 1
Hi everybody!

I have a problem when adding object list "message.addRegion(region)", it is just running "select * from MessageRegion where region = 37 ", where property lazy = false that collections


Code:
/**
     *  @hibernate.set
     *      table="MessagesRegions"
     *      inverse="true"
     *      cascade="save-update"
     *      lazy="true"
     *  @hibernate.collection-key
     *      column="message"
     *  @hibernate.collection-many-to-many
     *      column="region"
     *      class="ar.com.tma.eb.olm.server.entity.message.MessageRegion"
     *   

     *   @hibernate.collection-cache
     *      usage="nonstrict-read-write"
    */
   public Set getRegions() {
      return regions;
   }
   public void setRegions(Set value) {
      regions = value;
   }
   public void addRegion(MessageRegion region) {
      if (region==null) {
         throw new IllegalArgumentException("null MessageRegion");
      }
      region.getMessages().add(this);
      getRegions().add(region);
   }


Code:

public MessageMIT updateEventMIT(User user,Integer eventId,MessageCategory category,MessageFunctionalGroup functionalGroup,
         MessageStatus status,Set regions,Set voiceNets,Set dataNets,Set channels,MessagePriority priority,String netElement,
         String product,MessageService service,String symptom,String place,Date start,Date finish,Date estimatedTime,String cause,
         String incidenceOther,Set incidences,String incidence,String speech,MessageScope scopes)
   throws MessageException {
      
      
      
      try {
         Session session = HFactory.currentSession();
         
         MessageMIT message = new MessageMIT();
         message.setDate(new Date());
         message.setUser(user);
         message.setCategory(category);
         message.setFunctionalGroup(functionalGroup);
         message.setMessageStatus(status);
         message.setChannelsAsSet(channels);
         message.setPriority(priority);
         message.setNetElement(netElement);
         message.setProduct(product);
         message.setService(service);
         message.setSymptom(symptom);
         message.setPlace(place);
         message.setStart(start);
         message.setFinish(finish);
         message.setEstimatedTime(estimatedTime);
         message.setCause(cause);         
         message.setIncidence(incidence);
         message.setSpeech(speech);
         message.setIncidenceOther(incidenceOther);
         message.setMessageScope(scopes);
         
         // create message
         session.save(message);
         session.flush();
         
         logger.debug("created message "+message.getId());
         // add regions
         for (Iterator it = regions.iterator(); it.hasNext();) {
            MessageRegion region = (MessageRegion) it.next();
            logger.debug("adding MessageRegion "+region.getId()+" to Message "+message.getId());
            message.addRegion(region);
         }
         // add voice nets
         for (Iterator it = voiceNets.iterator(); it.hasNext();) {
            MessageVoiceNet voiceNet = (MessageVoiceNet) it.next();
            logger.debug("adding MessageVoiceNet "+voiceNet.getId()+" to Message "+message.getId());
            message.addVoiceNet(voiceNet);
         }
         // add data nets
         for (Iterator it = dataNets.iterator(); it.hasNext();) {
            MessageDataNet dataNet = (MessageDataNet) it.next();
            logger.debug("adding MessageDataNet "+dataNet.getId()+" to Message "+message.getId());
            message.addDataNet(dataNet);
         }
         // add incidences
         for (Iterator it = incidences.iterator(); it.hasNext();) {
            MessageIncidence messageIncidence = (MessageIncidence) it.next();
            logger.debug("adding MessageIncidence "+messageIncidence.getId()+" to Message "+message.getId());
            message.addIncidence(messageIncidence);
         }

         // setup eventId
         if (eventId==null) {
            message.setEventId(message.getId());
         }
         else {
            message.setEventId(eventId);
         }
         // update message
         session.update(message);
         session.flush();
         
         
         logger.debug("created/updated message MIT id:"+message.getId()+" eventId:"+message.getEventId());
         displayEventCreation(message);
         return (MessageMIT) message;
      } catch (HibernateException e) {
         logger.error("error creating event MIT");
         e.printStackTrace();
         
         throw new MessageException();
      }
   }






I have to follow the result in my code :
Code:
2009-09-16 16:05:43,873|DEBUG|created message 60466
2009-09-16 16:05:43,873|DEBUG|adding MessageRegion 37 to Message 60466
2009-09-16 16:05:43,873|DEBUG|initializing collection [ar.com.tma.eb.olm.server.entity.message.MessageRegion.messages#37]
2009-09-16 16:05:43,873|DEBUG|checking second-level cache
2009-09-16 16:05:43,873|DEBUG|collection not cached
2009-09-16 16:05:43,873|DEBUG|loading collection: [ar.com.tma.eb.olm.server.entity.message.MessageRegion.messages#37]
2009-09-16 16:05:43,873|DEBUG|about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2009-09-16 16:05:43,873|DEBUG|select messages0_.region as region0_, messages0_.message as message0_ from MessagesRegions messages0_ where messages0_.region=?
2009-09-16 16:05:43,873|DEBUG|preparing statement
2009-09-16 16:05:43,873|DEBUG|binding '37' to parameter: 1
2009-09-16 16:05:43,889|DEBUG|about to open ResultSet (open ResultSets: 0, globally: 0)
2009-09-16 16:05:43,889|DEBUG|result set contains (possibly empty) collection: [ar.com.tma.eb.olm.server.entity.message.MessageRegion.messages#37]
2009-09-16 16:05:43,889|DEBUG|uninitialized collection: initializing
2009-09-16 16:05:43,889|DEBUG|processing result set
2009-09-16 16:05:43,889|DEBUG|result set row: 0
2009-09-16 16:05:43,889|DEBUG|result row:
2009-09-16 16:05:43,889|DEBUG|returning '37' as column: region0_
2009-09-16 16:05:43,889|DEBUG|found row of collection: [ar.com.tma.eb.olm.server.entity.message.MessageRegion.messages#37]
2009-09-16 16:05:43,889|DEBUG|reading row
2009-09-16 16:05:43,889|DEBUG|returning '20986' as column: message0_
2009-09-16 16:05:43,889|DEBUG|loading entity: [ar.com.tma.eb.olm.server.entity.message.MessageMIT#20986]
2009-09-16 16:05:43,889|DEBUG|creating new proxy for entity
2009-09-16 16:05:43,889|DEBUG|result set row: 1
2009-09-16 16:05:43,889|DEBUG|result row:
2009-09-16 16:05:43,889|DEBUG|returning '37' as column: region0_
2009-09-16 16:05:43,889|DEBUG|found row of collection: [ar.com.tma.eb.olm.server.entity.message.MessageRegion.messages#37]
2009-09-16 16:05:43,889|DEBUG|reading row
2009-09-16 16:05:43,889|DEBUG|returning '20988' as column: message0_
2009-09-16 16:05:43,889|DEBUG|loading entity: [ar.com.tma.eb.olm.server.entity.message.MessageMIT#20988]
2009-09-16 16:05:43,889|DEBUG|creating new proxy for entity
2009-09-16 16:05:43,889|DEBUG|result set row: 2
2009-09-16 16:05:43,889|DEBUG|result row:
2009-09-16 16:05:43,889|DEBUG|returning '37' as column: region0_
2009-09-16 16:05:43,889|DEBUG|found row of collection: [ar.com.tma.eb.olm.server.entity.message.MessageRegion.messages#37]
2009-09-16 16:05:43,889|DEBUG|reading row
2009-09-16 16:05:43,889|DEBUG|returning '20989' as column: message0_
2009-09-16 16:05:43,889|DEBUG|loading entity: [ar.com.tma.eb.olm.server.entity.message.MessageMIT#20989]
2009-09-16 16:05:43,889|DEBUG|creating new proxy for entity
2009-09-16 16:05:43,889|DEBUG|result set row: 3
2009-09-16 16:05:43,889|DEBUG|result row:
2009-09-16 16:05:43,889|DEBUG|returning '37' as column: region0_
2009-09-16 16:05:43,889|DEBUG|found row of collection: [ar.com.tma.eb.olm.server.entity.message.MessageRegion.messages#37]
2009-09-16 16:05:43,889|DEBUG|reading row
2009-09-16 16:05:43,889|DEBUG|returning '20992' as column: message0_
2009-09-16 16:05:43,889|DEBUG|loading entity: [ar.com.tma.eb.olm.server.entity.message.MessageMIT#20992]
2009-09-16 16:05:43,889|DEBUG|creating new proxy for entity
2009-09-16 16:05:43,889|DEBUG|result set row: 4
2009-09-16 16:05:43,889|DEBUG|result row:
2009-09-16 16:05:43,889|DEBUG|returning '37' as column: region0_
2009-09-16 16:05:43,889|DEBUG|found row of collection: [ar.com.tma.eb.olm.server.entity.message.MessageRegion.messages#37]
2009-09-16 16:05:43,889|DEBUG|reading row
2009-09-16 16:05:43,905|DEBUG|returning '20997' as column: message0_
2009-09-16 16:05:43,905|DEBUG|loading entity: [ar.com.tma.eb.olm.server.entity.message.MessageMIT#20997]
2009-09-16 16:05:43,905|DEBUG|creating new proxy for entity
2009-09-16 16:05:43,905|DEBUG|result set row: 5
2009-09-16 16:05:43,905|DEBUG|result row:
2009-09-16 16:05:43,905|DEBUG|returning '37' as column: region0_
2009-09-16 16:05:43,905|DEBUG|found row of collection: [ar.com.tma.eb.olm.server.entity.message.MessageRegion.messages#37]
2009-09-16 16:05:43,905|DEBUG|reading row
2009-09-16 16:05:43,905|DEBUG|returning '20998' as column: message0_
2009-09-16 16:05:43,905|DEBUG|loading entity: [ar.com.tma.eb.olm.server.entity.message.MessageMIT#20998]



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.