You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by 蔡博至 <Do...@dsc.com.tw> on 2003/06/12 08:51:00 UTC

Problem of dynamic proxy?

Hi!
    I declare a class-descriptor of A. Its proxy property is set dynamic. I try to load it from DB by oql command. The return collection is DList(because the OqlCollectionClass=org.apache.ojb.odmg.collections.DListImpl is set in OJB.properties), but the elements in DList are proxy objects not A. How can I get A from DList except that I must not set A proxy property dynamic?

A class descript:
 <class-descriptor class="A" table="A" proxy="dynamic">
    :
    :
    :
 </class-descriptor>

oql command : "select o from A"

Using ODMG:

1         String pQueryString = "select o from A";
2         DList tResult = null;
3         try {
4             Transaction tx = this.odmg.currentTransaction();
5             OQLQuery tQuery = this.odmg.newOQLQuery(); 
6             tQuery.create(pQueryString); 
7             tResult = (DList)tQuery.execute(); 
8         } catch (Exception e) {
9             e.printStackTrace();
10            throw new DBServerException(e.getMessage());
11        } 
12        Iterator tIter = tResult.iterator();
13        while (tIter.hasNext()){
14            A tA = (A)tIter.next();
                :
                :
        }
        
I got a error message :"java.lang.ClassCastException: $Proxy119"  on line 14.

Re: Problem of dynamic proxy?

Posted by Marcus Breese <ma...@breese.com>.
Are there any other requirements of this?  Because I have a similar 
situation, and there isn't any sample code on the website.

I'm trying to use Dynamic proxies,  My tables are setup as such:

TableName (derived object for business rules), implements 
TableNameInterface
	|
	|-- TableNameCO ( derived object for collections to be placed in ) , 
implements TableNameCOInterface
		|
		|-- TableNameBO (base object - all table fields go here) , implements 
TableNameBOInterface
			|
			|-- BaseObject (super object - contains a custom toString that 
dynamically prints this object's contents)

TableNameInterface extends TableNameCOInterface
TableNameCOInterface extends TableNameBOInterface

TableNameBOInterface includes all getColumn and setColumn definitions.

Now, I'm attempting to load an object by criteria,
<code>
		Criteria crit = new Criteria();
		crit.addEqualTo("username",u);
		crit.addEqualTo("password",new MD5(p));
		
		Query q = QueryFactory.newQuery(AclUser.class,crit);
		
		AclUserInterface IUser=null;
		try {
			
			/* WORKS */
			Object obj = broker.getObjectByQuery(q);		
			
			/* Throws ClassCastException */
			IUser = (AclUserInterface) broker.getObjectByQuery(q);
		} catch { .... }	
</code>



Now, if I do a System.out.println(obj), I get the full object record as 
it should be... complete with the collections (thanks to my toString() 
in BaseObject).
But the IUser conversion dies.

Am I just an idiot?  I've been playing with this for 2 days and have no 
clue... any assistance would be appreciated.  I think that there should 
be some sample code for this included in the Tutorial, as this is 
probably a feature that people will want to use.


===============================

Here are the appropriate snippets from my repository file (for table 
AclUser)

<class-descriptor
     class="edu.iupui.cmg.labratj.om.AclUserCO"
     proxy="dynamic"
 >
     <extent-class class-ref="edu.iupui.cmg.labratj.om.AclUser"/>
</class-descriptor>
<class-descriptor
     class="edu.iupui.cmg.labratj.om.AclUserBO"
 >
     <extent-class class-ref="edu.iupui.cmg.labratj.om.AclUserCO"/>
</class-descriptor>
<class-descriptor
     class="edu.iupui.cmg.labratj.om.AclUser"
     proxy="dynamic"
     table="acl_user"
 >
     <field-descriptor
         name="id"
         column="id"
         jdbc-type="INTEGER"
         primarykey="true"
         nullable="false"
         autoincrement="true"
     >
     </field-descriptor>
     <field-descriptor
         name="username"
         column="username"
         jdbc-type="VARCHAR"
         nullable="false"
     >
     </field-descriptor>
     <field-descriptor
         name="password"
         column="password"
         jdbc-type="VARCHAR"
         nullable="false"
     >
     </field-descriptor>
     <field-descriptor
         name="first"
         column="first"
         jdbc-type="VARCHAR"
         nullable="false"
     >
     </field-descriptor>
     <field-descriptor
         name="last"
         column="last"
         jdbc-type="VARCHAR"
         nullable="false"
     >
     </field-descriptor>
     <field-descriptor
         name="email"
         column="email"
         jdbc-type="VARCHAR"
         nullable="false"
     >
     </field-descriptor>
</class-descriptor>



On Thursday, June 12, 2003, at 02:18  PM, vinicius.bomfim@globo.com 
wrote:

>
>    You have to create an interface and your class implement that 
> interface.
>
>   And then you have to cast whith that interface.
>
>     IA tA = (A)tIter.next();
>
> Vinicius Bomfim
>
-=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-=-
Marcus Breese                            mbreese@iupui.edu
IU School of Medicine              marcus@breese.com
Dept. of Biochemistry and Molecular Biology
Center for Medical Genomics / Grow Lab



RE: Problem of dynamic proxy?

Posted by vi...@globo.com.
Hi,

   You have to create an interface and your class implement that interface.

  And then you have to cast whith that interface.
  
    IA tA = (A)tIter.next();

Vinicius Bomfim


 '>'-- Mensagem Original --
 '>'Reply-To: "OJB Users List" <oj...@db.apache.org>
 '>'Reply-To: ??? <Do...@dsc.com.tw>
 '>'From: ??? <Do...@dsc.com.tw>
 '>'To: "OJB Users List" <oj...@db.apache.org>
 '>'Subject: Problem of dynamic proxy? 
 '>'Date: Thu, 12 Jun 2003 14:51:00 +0800
 '>'
 '>'
 '>'Hi!
 '>'    I declare a class-descriptor of A. Its proxy property is set dynamic.
 '>'I try to load it from DB by oql command. The return collection is DList(because
 '>'the OqlCollectionClass=org.apache.ojb.odmg.collections.DListImpl is
set in
 '>'OJB.properties), but the elements in DList are proxy objects not A.
How can
 '>'I get A from DList except that I must not set A proxy property dynamic?
 '>'
 '>'A class descript:
 '>' <class-descriptor class="A" table="A" proxy="dynamic">
 '>'    :
 '>'    :
 '>'    :
 '>' </class-descriptor>
 '>'
 '>'oql command : "select o from A"
 '>'
 '>'Using ODMG:
 '>'
 '>'1         String pQueryString = "select o from A";
 '>'2         DList tResult = null;
 '>'3         try {
 '>'4             Transaction tx = this.odmg.currentTransaction();
 '>'5             OQLQuery tQuery = this.odmg.newOQLQuery(); 
 '>'6             tQuery.create(pQueryString); 
 '>'7             tResult = (DList)tQuery.execute(); 
 '>'8         } catch (Exception e) {
 '>'9             e.printStackTrace();
 '>'10            throw new DBServerException(e.getMessage());
 '>'11        } 
 '>'12        Iterator tIter = tResult.iterator();
 '>'13        while (tIter.hasNext()){
 '>'14            ? tA = (A)tIter.next();
 '>'                :
 '>'                :
 '>'        }
 '>'        
 '>'I got a error message :"java.lang.ClassCastException: $Proxy119"  on
line
 '>'14.