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.