-->
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: Automatic update of a transient (?) field (entity)
PostPosted: Sun Jun 05, 2011 2:58 pm 
Newbie

Joined: Sun Feb 06, 2011 12:42 pm
Posts: 2
Hi

i am new to hibernate an currently working on a private project. So please excuse if i still have trouble understanding some principles (which is, with this question, something i expect)...

My Problem:
I have 2 entities
  • DataLabel
  • DataFlags (the cardinality should be 1..*, not 1)
Image
When i load the DataLabel element i only want to load the elements from DataFlags where the BaseLine matches and not all. Hence i wrote this code:
Code:
public class DataLabel {
   ...
    @Transient
   public DataFlag getFlags(final IBaseLine bl) {
      DataFlag flags = storedFlags.get(bl);
      if (flags == null) {
         final String hql = "from DataFlag df where df.ref = :entityKey and df.baseLine = :baseline ";

         final ISessionProvider sp = Services.getService(ISessionProvider.class);
         final Session session = sp.getSession();

         final Query query = session.createQuery(hql);
         query.setInteger("entityKey", getEntityKey());
         query.setInteger("baseline", bl == null ? null : bl.getId());
         flags = (DataFlag) query.uniqueResult();

         storedFlags.put(bl, flags);
      }
      return flags;
   }
   ...
}


What i now want, that when i call save on DataLabel that all elements within the map storedFlags are also saved/deleted.

Is that possible? If yes, how? Or is there a better way to get only the elements i need from DataFlags?

Thanks
Matthias


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.