-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hierarchy structure vs. collection mapping
PostPosted: Sun Jun 21, 2009 7:01 pm 
Regular
Regular

Joined: Tue Feb 17, 2009 3:36 pm
Posts: 78
Here is the hierarchy structure:

Code:
@MappedSuperclass
@Entity
@Table(name = "group")
public class GroupInfo implements Serializable {

   protected Integer id;
//...
   @Basic
   @Id
   @javax.persistence.SequenceGenerator(name = "group_id_sequence", sequenceName = "se_group_id_seq")
   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "group_id_sequence")
   @Column(name = "id")
   public Integer getId() {
      return id;
   }

   public void setId(Integer id) {
      this.id = id;
   }
// ...
}

Its subclass, Group, is defined as the following:
Code:
@Entity
@Table(name = "group")
public class Group extends GroupInfo {

// ....
   private Set<Membership> memberships;
// ...
   @OneToMany(fetch = FetchType.LAZY, mappedBy = "pk.group")
   protected Set<Membership> getMembershipsInternal() {
      if (memberships == null)
         memberships = new HashSet<Membership>();
      return memberships;
   }
// ...
}

where the Membership class is defined as:
Code:
@Entity
@Table(name = "membership")
@AssociationOverrides({
@AssociationOverride(name = "pk.user", joinColumns = @JoinColumn(name = "user_fk")),
@AssociationOverride(name = "pk.group", joinColumns = @JoinColumn(name = "group_fk"))
        })
public class Membership implements Serializable {

// ...
   private UserGroupCompoundKey pk;
// ...
   @EmbeddedId
   public UserGroupCompoundKey getPk() {
      return pk;
   }
// ...
}

the compound key is defined as:
Code:
@Embeddable
public class UserGroupCompoundKey implements Serializable {

   private UserInfo user;
   private GroupInfo group;
//...
   @ManyToOne
   public GroupInfo getGroup() {
      return group;
   }
//...
}

The above can pass the deployment. Now, I need to have one more top super class as:
Code:
@MappedSuperclass
@Entity
@Inheritance(strategy= InheritanceType.TABLE_PER_CLASS)
public class AbstractSecureObject implements Serializable {

   @Basic
    @Id
    @GeneratedValue
    protected Integer id;   
//...
}

And I need to modify the GroupInfo class accordingly.
Code:
public class GroupInfo extends AbstractSecureObject {

//   protected Integer id;
// remove the getter and setter of id
}

With the above changes, I run into an exception:
Quote:
...
Caused by: org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: group, for columns: [org.hibernate.mapping.Column(memberships)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:292)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:276)
at org.hibernate.mapping.Property.isValid(Property.java:207)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:458)
at org.hibernate.mapping.RootClass.validate(RootClass.java:215)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1135)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1320)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:814)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:732)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
... 66 more

I can't see how this exception relates with the hierarchy change.
Can someone help me out of this problem?


Top
 Profile  
 
 Post subject: Re: Hierarchy structure vs. collection mapping
PostPosted: Mon Jun 22, 2009 4:21 pm 
Regular
Regular

Joined: Tue Feb 17, 2009 3:36 pm
Posts: 78
Anyone?


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