-->
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: annotations and composite key mapping to objects
PostPosted: Mon Jan 17, 2005 3:03 pm 
Beginner
Beginner

Joined: Fri Jun 11, 2004 3:42 am
Posts: 22
Hi,

I am trying to get this code working with the limited knowledge I have of
EJB3. Can some one point out where I am wrong?

Quote:
This is a Group Node that can have more than one parent and more than one children


Code:
@Entity(name="GroupNode", access = AccessType.FIELD)
@Table(name="GroupNode")
public class GroupNode {
   @Id
   @Column(name="`GroupNodeID`", length=100)
       public String GroupNodeID = new String();

   @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
   @JoinColumn(name="ChildGroupID")
   public Set<GroupNodeRelationship> Parents = new HashSet();

   @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
   @JoinColumn(name="ParentGroupID")
   public Set<GroupNodeRelationship> Children = new HashSet();

         ....................... more code here

}


Quote:
This defines the relationship


Code:
@Entity(name="GroupNodeRelationship", access = AccessType.FIELD)
@Table(name="GroupNodeRelationship")
public class GroupNodeRelationship {
   @Id(generate = GeneratorType.NONE)
   @Dependent({@DependentAttribute(name = "ParentGroupID"), @DependentAttribute(name = "ChildGroupID")})
   public GroupNodeRelationshipPk GroupNodeRelationshipPkObj = new GroupNodeRelationshipPk();

         ....................... more code here

}


Quote:
This defines the primary key for the relationship so that a node is not mapped twice (parent or children)

Code:
@DependentObject(access = AccessType.FIELD)
public class GroupNodeRelationshipPk {

   @ManyToOne(cascade = CascadeType.ALL)
   @Column(name="ParentGroupID")
   public GroupNode ParentGroupObject = null;
   
   @ManyToOne(cascade = CascadeType.ALL)
   @Column(name="ChildGroupID")
   public GroupNode ChildGroupObject = null;
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 18, 2005 6:51 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
ManyToOne inside a dependent object is not supported by th spec.
You should put your ManyToOne in GroupNodeRelationship and set them insertable=false, updatable=false

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 19, 2005 4:58 am 
Beginner
Beginner

Joined: Fri Jun 11, 2004 3:42 am
Posts: 22
I tried your suggestion. The new Structure looks like this:

Code:
@Entity(name="GroupNode", access = AccessType.FIELD)
@Table(name="GroupNode")
public class GroupNode {

   @Id
   @Column(name="`ID`", length=100)
        public String ID = new String();

   @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
   @JoinColumn(name="ChildGroupID")
   public Set<GroupNodeRelationship> Parents = new HashSet();

   @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
   @JoinColumn(name="ParentGroupID")
   public Set<GroupNodeRelationship> Children = new HashSet();
}



Code:
@Entity(name="GroupNodeRelationship", access = AccessType.FIELD)
@Table(name="GroupNodeRelationship")
public class GroupNodeRelationship {

   @Id
   @Column(name="`ID`", length=100)
   public String ID = new String();

   @ManyToOne(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
   @JoinColumn(name="ChildGroupID", insertable=false, updatable=false)
   public GroupNode ChildGroupObject = null;

   @ManyToOne(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
   @JoinColumn(name="ParentGroupID", insertable=false, updatable=false)
   public GroupNode ParentGroupObject = null;

   @OneToOne(cascade = CascadeType.ALL, fetch=FetchType.EAGER)
   @JoinColumn(name="`ParentGroupThatOwnsThisLeaf`")
   public GroupNode GroupOwner = null;

}


Now, when I make a query to retrieve GroupNodeRelationship records, ChildGroupObject , ParentGroupObject , GroupOwner is not filled ! OneToMany works but with the same structure, ManyToOne is not filling the right Feilds!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 19, 2005 11:00 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Still keep GroupNodeRelationshipPk as a PK and map the ids inside it

Code:
@DependentObject(access = AccessType.FIELD)
public class GroupNodeRelationshipPk {

   @Column(name="ParentGroupID")
   public Integer ParentGroupId = null;
   
   @Column(name="ChildGroupID")
   public GroupNode ChildGroupId = null;
}

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 19, 2005 11:36 am 
Beginner
Beginner

Joined: Fri Jun 11, 2004 3:42 am
Posts: 22
I tried this and it does not still seem to work:

Code:
@Entity(name="GroupNode", access = AccessType.FIELD)
@Table(name="GroupNode")
public class GroupNode {

   @Id
   @Column(name="`ID`", length=100)
   public String ID = new String();

   @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
   @JoinColumn(name="ChildGroupID")
   public Set<GroupNodeRelationship> Parents = new HashSet();

   @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
   @JoinColumn(name="ParentGroupID")
   public Set<GroupNodeRelationship> Children = new HashSet();
}


Code:
@Entity(name="GroupNodeRelationship", access = AccessType.FIELD)
@Table(name="GroupNodeRelationship")
public class GroupNodeRelationship {

   @Id(generate = GeneratorType.NONE)
   @Dependent({@DependentAttribute(name = "ParentGroupID", column = @Column(name="`ParentGroupID1`")), @DependentAttribute(name = "ChildGroupID", column = @Column(name="`ParentGroupID`"))})
   public GroupNodeRelationshipPk GroupNodeRelationshipPkObj = null;
   
   @OneToOne(cascade = CascadeType.ALL, fetch=FetchType.EAGER)
   @JoinColumn(name="`ParentGroupThatOwnsThisLeaf`")
   public GroupNode ParentGroupThatOwnsThisLeaf = null;
}


Code:
@DependentObject(access = AccessType.FIELD)
public class GroupNodeRelationshipPk {

   @Column(name="ParentGroupID")
   public GroupNode ParentGroupObj = null;
   
   @Column(name="ChildGroupID")
   public GroupNode ChildGroupObj = null;
}


The exception I get is

Quote:
org.hibernate.MappingException: Could not determine type for: com.agileflow.affs.AFFSGroup.GroupNode, for columns: [org.hibernate.mapping.Column(ParentGroupID)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:215)
at org.hibernate.mapping.Property.getType(Property.java:38)
at org.hibernate.mapping.Component.getType(Component.java:150)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:202)
at org.hibernate.mapping.RootClass.validate(RootClass.java:186)
at org.hibernate.cfg.Configuration.validate(Configuration.java:750)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:985)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 21, 2005 10:34 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Come on! you join columns name does not match the defined column names in you @Dependent annotation

_________________
Emmanuel


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.