-->
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: Association table mapping problem with composite-element
PostPosted: Fri May 20, 2005 5:43 am 
Newbie

Joined: Mon Apr 11, 2005 4:55 am
Posts: 16
Hi all,

I want to map the J2EE security model, which say that a User may have a collection of Roles. But I have an exception thrown, telling me that the Role object is not an instance of declaring class. Maybe my error is evident, but I cannot see anything wrong.

My database design use 3 tables (user, role, and userrole)
The userrole table has a primary key composed by the 2 foreign key (of user and role) and has also some additional columns.

My Java design use 2 classes (ApplicationUserBean and J2EERoleImpl ). The User has a Set of Roles as an attribute. Following the excellent "Hibernate In Action" book, page 229, I added a 3rd classe to hold the association (J2EEUserRoleImpl).

Java POJOs:

A User, with a set of role :
Code:
public class ApplicationUserBean extends GenericBusinessBean implements ApplicationUser {

   private BusinessBean foreignReference;
   private String fullName;
   private String j2EEUserName;
   private String j2EEPassword;
   private Set<J2EERoleImpl> j2EERoles;
//...getters and setters follow


...a Role :

Code:
public class J2EERoleImpl extends GenericBusinessBean {
   
   private String j2EERoleName;
//...getters and setters follow


...and the association classe :

Code:
public class J2EEUserRoleImpl {

   private ApplicationUserBean user;
   private J2EERoleImpl role;
   private String userName;
   private String roleName;
//...getters and setters follow

Mapping documents:

The Role mapping :
Code:
    <class name="J2EERoleImpl" table="role" lazy="false">
          
        <id name="id" column="id_role" type="long" unsaved-value="0" >
            <generator class="identity" />
        </id>       
           
        <property name="j2EERoleName" column="nom_role" type="string" not-null="true"/>
       

    </class>


and the User mapping, which hold a set of composite elements :

Code:
    <class name="ApplicationUserBean" table="utilisateur" lazy="false">
          
        <id name="id" column="id_utilisateur" type="long" unsaved-value="0" >
            <generator class="identity" />
        </id>       
           
        <property name="j2EEUserName" column="nom_utilisateur" type="string" not-null="true"/>
        <property name="j2EEPassword" column="mot_de_passe" type="string" not-null="true"/>
       
          <!-- CLES ETRANGERES  -->   
         <many-to-one
            name="foreignReference"
            column="id_contact"
            class="com.netqi.business.beans.misc.Person"
            cascade="none"
            not-null="true"
            unique="true"
         />   
         
      <set name="j2EERoles" lazy="false" table="role_utilisateur" cascade="all">
         <key column="id_utilisateur"/>

         <composite-element class="J2EEUserRoleImpl">
            <parent name="user"/>
            <many-to-one name="role"
               class="J2EERoleImpl"
               column="id_role"
               not-null="true"/>
            <property name="userName" column="nom_utilisateur" not-null="true"/>
            <property name="roleName" column="nom_role" not-null="true"/>
         </composite-element>
      </set>
            
    </class>


Full stack trace of any exception that occurs:

11:25:09 ERROR [org.hibernate.property.BasicPropertyAccessor] --> IllegalArgumentException in class: com.netqi.business.beans.security.J2EEUserRoleImpl, getter method of property: role
11:25:09 FATAL [com.netqi.persistence.hibernate.HibernateDAO] --> Problem while saving a bean
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.netqi.business.beans.security.J2EEUserRoleImpl.role
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:119)
at org.hibernate.tuple.AbstractComponentTuplizer.getPropertyValue(AbstractComponentTuplizer.java:61)
at org.hibernate.tuple.AbstractComponentTuplizer.getPropertyValues(AbstractComponentTuplizer.java:67)
//...

Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:105)
Hibernate version: 3.0


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.