-->
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: How to map the other side of an @Any relationship
PostPosted: Mon Jan 04, 2010 5:36 pm 
Newbie

Joined: Mon Jan 04, 2010 5:02 pm
Posts: 1
I have a situation where a persistent object can be 'owned' by one of several classes that implement a given interface.

I have used the @Any annotation to successfully map the 'child' portion of the relationship (see class Attribute Group below).

What I cannot seem to get to work is the 'parent' side of the relationship. (see class AdhocMaterialGroup below)

When I attempt to run this, the exception at start up is:
org.hibernate.MappingException: Foreign key (FK4E0B69636E7AFB69:AttributeGroup [ownerType,ownerId])) must have same number of columns as the referenced primary key (AdhocMaterialGroup [id])

If I comment out the references in AdhocMaterialGroup to AttributeGroup, SchemaExport can run successfully.

How can I map the parent -> child side when the child maps the parent as @Any?

Environment:
Tomcat 6.0.20/Hibernate Annotations 3.4.0.GA/Hibernate 3.3.2.GA/Hibernate Commons Annotations 3.1.0.GA/Spring 2.5.6

Relevant portions of these classes :
Code:


@Entity
@Table(name = "AttributeGroup")
public class AttributeGroup extends AbstractEditableObject
{
   ...
   @Any(metaColumn = @Column(name = "ownerType"), fetch = FetchType.LAZY)
   @AnyMetaDef(idType = "string", metaType = "string", metaValues =
      {
            @MetaValue(value = "InventoryClass", targetEntity = InventoryClass.class),
            @MetaValue(value = "InventorySubClass", targetEntity = InventorySubClass.class),
            @MetaValue(value = "AdhocMaterialGroup", targetEntity = AdhocMaterialGroup.class)
      }
   )
   @JoinColumn(name = "ownerId")
   private AttributeGroupOwner owner;
...
}

@Entity
@Table(name = "AdhocMaterialGroup")
public class AdhocMaterialGroup extends AbstractEditableObject implements AttributeGroupOwner
{
...
   @OneToMany(fetch = FetchType.EAGER,  targetEntity = AttributeGroup.class, mappedBy = "owner")
   private Set<AttributeGroup> attributeGroups = new HashSet<AttributeGroup>(0);
...
}

@MappedSuperclass
public abstract class AbstractEditableObject implements EditableObject
{   ...
   @Id
   @GenericGenerator(name = "guid", strategy = "guid")
   @GeneratedValue(generator = "guid")
   @Column(name = "id", unique = true, nullable = false, updatable = false, columnDefinition = "uniqueidentifier")
   private String id;
   ...
}

public interface AttributeGroupOwner
{

   public Set<AttributeGroup> getAttributeGroups();

   public void setAttributeGroups(Set<AttributeGroup> attributeGroups);
}


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.