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.  [ 3 posts ] 
Author Message
 Post subject: many to many with association table
PostPosted: Mon May 29, 2006 2:55 am 
Beginner
Beginner

Joined: Sat Mar 04, 2006 1:07 am
Posts: 27
Sorry - this was meant to be in the Hibernate Users forum.


I have user and role tables with a junction table that has the primary keys of the usr_id and role_id, along with some extra fields. This is very similar to what is described in http://forum.hibernate.org/viewtopic.php?t=959196&highlight=compositeelement and in section 6.3.2 of Hibernate in Action (p 229). I have used a composite element to map the extra fields, which are the username and date created.

User declares a Set of Roles:
Code:
   private Set<Role> roles = new LinkedHashSet<Role>();


and has a public getter and setter for the Roles Set and also an addRole method which takes a Role object as its parameter.


The extra java class used in the composite-element is as follows:

Code:
public class UserRole  implements Serializable {
   private User user;
   private Role role;
   private String userIdCreate = Utils.getUsername();
   private Date dateCreate = new Date();

   public UserRole() {
   }

   public Date getDateCreate() {
      return dateCreate;
   }

   public Role getRole() {
      return role;
   }

   public User getUser() {
      return user;
   }

   public String getUserIdCreate() {
      return userIdCreate;
   }

   public void setUser(User user) {
      this.user = user;
   }

   public void setRole(Role role) {
      this.role = role;
   }
   
}


The mapping for User has this:
Code:
<hibernate-mapping auto-import="true" default-lazy="false">
   <class name="au.com.woolworths.hrportal.user.User" table="USR">
...
      <set name="roles" table="USR_ROLE_XREF" cascade="all" access="field" lazy="true">
         <key column="USR_ID" not-null="true"/>
         <composite-element class="au.com.woolworths.hrportal.user.component.UserRole">
            <many-to-one name="role" class="au.com.woolworths.hrportal.user.role.Role" column="ROLE_ID" access="field"/>
            <property name="userIdCreate" column="CRE_USR_ID" />
            <property name="dateCreate" column="CRE_DTETM"   />
         </composite-element>
      </set>
...


When I try to cerate a new User containing Roles, I get the following exception:

Code:
org.springframework.orm.hibernate3.HibernateSystemException: could not get a field value by reflection getter of au.com.woolworths.hrportal.user.component.UserRole.role; nested exception is org.hibernate.PropertyAccessException: could not get a field value by reflection getter of au.com.woolworths.hrportal.user.component.UserRole.role


I've been struggling with this all day and I don't know why it doesn't work.
Any suggestions would be appreciated
Thanks
Alan


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 29, 2008 5:51 am 
Newbie

Joined: Tue Apr 29, 2008 5:47 am
Posts: 1
Location: Kiev
Could you please tell how did you solve this problem?


Top
 Profile  
 
 Post subject: Solution?
PostPosted: Sun Jun 01, 2008 2:07 am 
Newbie

Joined: Sun Jun 01, 2008 1:58 am
Posts: 1
Anyone found the solution?


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