-->
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: is it possible for a bag to return a class i define
PostPosted: Wed Jan 12, 2011 5:15 am 
Newbie

Joined: Wed Jan 12, 2011 2:42 am
Posts: 4
Hi,

in my other topic https://forum.hibernate.org/viewtopic.php?f=1&t=1009053 i tried to explain what i wanted and actually kinda solved it. but for some of my data i need to use collections which are actually a single data. i worked the way around by changing getters and setters like below but is it possible to make bag return a class i want instead of a collection (or is there anything else that does it)

here is bag:
Code:
<bag name="displayHeader" inverse="true" cascade="all" lazy="false" where="typ = 2 and object_id = 1">
   <key column="template_id" not-null="true" />
   <one-to-many class="com.overteam.framework.persistent.NewsletterTemplateSettingsData"  not-found="ignore" />
</bag>



here is way i changed my getter and setter:
Code:
   public List<NewsletterTemplateSettingsData> getDisplayHeader(){
      List<NewsletterTemplateSettingsData> list = new LinkedList<NewsletterTemplateSettingsData>();
      list.add(displayHeader);
      
      return list;
   }
   public NewsletterTemplateSettingsData getDisplayHeaderObject() {
      return displayHeader;
   }
   public void setDisplayHeader(Object displayHeader) {
      if(displayHeader.getClass().equals(NewsletterTemplateSettingsData.class))
         this.displayHeader = (NewsletterTemplateSettingsData) displayHeader;
      else if(displayHeader.getClass().equals(PersistentBag.class)){
         List<NewsletterTemplateSettingsData> list = (List<NewsletterTemplateSettingsData>) displayHeader;
         this.displayHeader = list != null && list.size() > 0 ? list.get(0) : null;
      }
   }



but to keep getters and setters in normal way


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.