Hi,

I have 2 classes: (HRDepartment & HREmployer)

--------------------------------------------------
HRDepartment implements IHRDepartment
HREmployer implements IHREmployer
--------------------------------------------------

there are relationships between them :
--------------------------------------------------
HRDepartment#manager : HREmployer
HRDepartment#employers : Collection (of HREmployer)

HREmployer#department : HRDepartment
HREmployer#manager : HREmployer
--------------------------------------------------

when I call getObjectByQuery() to get an instance of
HRDepartment
OJB had executed many SQL statments : 
--------------------------------------------------
1. materialize the department
  1.1. materialize the manager of the department
    1.1.1. materialize the deparment of the manager
      ...
    1.1.2. materialize the manager of the manager
      ...
  1.2. materialize the employers of the department
    1.2.1 materialize each employers for the
department
      ...
--------------------------------------------------

I try to use dynamic proxy to avoid the recursive
materialization
--------------------------------------------------
<class-descriptor
    class="xxx.HRDepartment"
    table="HR_ORG"
    proxy="true"
>
...
    <reference-descriptor
        name="manager"
        class-ref="xxx.HREmployer"
        proxy="true"
    >
        <foreignkey field-ref="managerId"/>
    </reference-descriptor>
    <collection-descriptor
        name="employers"
        element-class-ref="xxx.HREmployer"
        proxy="true"
    >
        <inverse-foreignkey field-ref="departmentId"/>
    </collection-descriptor>
</class-descriptor>

<class-descriptor
    class="xxx.HREmployer"
    table="HR_EMP"
    proxy="dynamic"
>
...
    <reference-descriptor
        name="department"
        class-ref="xxx.HRDepartment"
        proxy="true"
    >
        <foreignkey field-ref="departmentId"/>
    </reference-descriptor>
    <reference-descriptor
        name="manager"
        class-ref="xxx.HREmployer"
        proxy="true"
    >
        <foreignkey field-ref="managerId"/>
    </reference-descriptor>
</class-descriptor>
--------------------------------------------------

when I call getObjectByQuery() to get an instance of
HRDepartment
I caught such exception :
--------------------------------------------------
java.lang.ClassCastException
        at
xxx.HRDepartmentDAO.findDepartmentById(HRDepartmentDAO.java:49)
        at xxx.Sample5.main(Sample5.java:18)
Exception in thread "main"
--------------------------------------------------

I found the dynamic proxy : 
--------------------------------------------------
implements xxx.IHRDepartment
extends java.lang.reflect.Proxy
--------------------------------------------------

so I can't cast to xxx.HRDepartment (I think)

then I try to cast to IHRDepartment and call getId()
of IHRDepartment
another exception threw : 
--------------------------------------------------
[PersistentField] ERROR: while set field: 
object class[ xxx.HRDepartment
target field: manager
target field type: class xxx.HREmployer
object value class: $Proxy1
object value: unmaterialized proxy for
xxx.HREmployer{019517}]
java.lang.IllegalArgumentException
        at
sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:63)
        at java.lang.reflect.Field.set(Field.java:519)
        ...
--------------------------------------------------

how to :
1. avoid the recursive materialization
2. use dynamic proxy correctly (how to config
repository-user.xml?)

thanks

__________________________________
Do you Yahoo!?
Yahoo! Mail SpamGuard - Read only the mail you want.
http://antispam.yahoo.com/tools

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to