Hi,
I am trying to map a composite pattern based hierarchy. I have the following classes:
* Interface 'Filter'
* Class 'CombinedFilter' containing a List<Filter>
* Class 'AbstractSingleFilter'
* Some implementation classes that subclass AbstractSingleFilter
I am using Hibernate Annotations 3.4.0. I already found out that you cannot use annotations and interfaces, so I created a hbm.xml file for my interface
Code:
<hibernate-mapping>
<class name="com.mycomp.domain.filter.Filter">
<id name="id"/>
</class>
</hibernate-mapping>
The combined filter class is mapped like this:
Code:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class CombinedFilter implements Filter
{
@Id
@Column(name = "Id")
private Long m_id;
@Column(name = "ChildFilters")
private List<Filter> m_filters;
@Column(name = "CombinationType")
private CombinationType m_combinationType;
@Column(name = "Name")
private String m_name;
This the AbstractSingleFilter:
Code:
@MappedSuperclass
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class AbstractSingleFilter implements Filter
{
@Id
@Column(name = "Id")
private Long m_id;
@Column(name = "Name")
private String m_name;
And this is a concrete implementation:
Code:
@Entity
@PrimaryKeyJoinColumn(name="AbstractSingleFilterId")
public class ZoneIdFilter extends AbstractSingleFilter
{
@Column(name = "ZoneId")
private int m_zoneId;
What do I need to annotate the m_filters variable in CombinedFilter with to make this work?
I found
this example but it has a slightly different hierarchy. It does not use an interface and it has a link back to the parent, which I don't have here.
regards,
Wim