-->
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.  [ 6 posts ] 
Author Message
 Post subject: mapping to inner class
PostPosted: Thu Mar 11, 2010 5:38 am 
Regular
Regular

Joined: Wed Mar 10, 2010 4:48 am
Posts: 106
The problem has changed, so I deleted my large posts.

Please, see the large post (sixth).


Last edited by aukemid on Thu Mar 11, 2010 10:38 am, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: org.hibernate.Query to Iterator
PostPosted: Thu Mar 11, 2010 5:58 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Please show the mapping of class LanguageString (especially its ManyToOne relations),
and tell which version of hibernate you are using, thanks.


Top
 Profile  
 
 Post subject: Re: org.hibernate.Query to Iterator
PostPosted: Thu Mar 11, 2010 6:11 am 
Regular
Regular

Joined: Wed Mar 10, 2010 4:48 am
Posts: 106
deleted


Last edited by aukemid on Thu Mar 11, 2010 10:39 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: org.hibernate.Query to Iterator
PostPosted: Thu Mar 11, 2010 6:30 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
On
https://www.hibernate.org/117.html#A35

there's documented that <key-many-to-one> mappings has some limitations.
There's also described how to do it better.


Top
 Profile  
 
 Post subject: Re: org.hibernate.Query to Iterator
PostPosted: Thu Mar 11, 2010 6:50 am 
Regular
Regular

Joined: Wed Mar 10, 2010 4:48 am
Posts: 106
deleted


Last edited by aukemid on Thu Mar 11, 2010 10:38 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: org.hibernate.Query to Iterator
PostPosted: Thu Mar 11, 2010 10:29 am 
Regular
Regular

Joined: Wed Mar 10, 2010 4:48 am
Posts: 106
I got a new error about overriding equals and hassCode. But the problem aint in those functions but it's in my mapping.

The problem is in line 6 of the mapping block.
Now I use: class="data.StoreRule"
But I need an inner class in data.StoreRule called Composite, but how do I call this?

Mapping:
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="data.StoreRule" table="storeRules">
      <composite-id name="composite" class="data.StoreRule">// class is the problem
         <key-many-to-one name="store" class="data.Store" column="store" />
         <key-many-to-one name="rule" class="data.Rule" column="rule" />
      </composite-id>
   </class>
</hibernate-mapping>

Java class:
Code:
package data;

import java.io.Serializable;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

public class StoreRule
{
   private Store store;
   private Rule rule;
   private Composite composite;
   
   public StoreRule(Store store, Rule rule)
   {
      this.store = store;
      this.rule = rule;
   }
   
   public StoreRule()
   {
      
   }
   
   public Store getStore()
   {
      return store;
   }
   
   public Rule getRule()
   {
      return rule;
   }
   
   public Composite getComposite()
   {
      return composite;
   }
   
   public void setStore(Store store)
   {
      this.store = store;
   }
   
   public void setRule(Rule rule)
   {
      this.rule = rule;
   }
   
   public void setComposite(Composite composite)
   {
      this.composite = composite;
   }
   
   public class Composite implements Serializable
   {
      private Store store;
      private Rule Rule;
      
      public Composite()
      {
         
      }
      
      public boolean equals(Object other)
      {
         if (other instanceof StoreRule)
         {
            StoreRule castOther = (StoreRule) other;
            return new EqualsBuilder().append(this.getStore(), castOther.getStore()).append(this.getRule(), castOther.getRule()).isEquals();
         }
         else
            return false;
      }
      
      public int hashCode()
      {
         return new HashCodeBuilder().append(getStore()).append(getRule()).toHashCode();
      }
      
      public Store getStore()
      {
         return store;
      }
      
      public Rule getRule()
      {
         return Rule;
      }
      
      public void setStore(Store store)
      {
         this.store = store;
      }
      
      public void setRule(Rule Rule)
      {
         this.Rule = Rule;
      }
   }
}


Solved it by moving Composite out of StoreRule.


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