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 Sherwin Lu <sh...@hotmail.com> on 2003/05/21 12:10:25 UTC

OJB Support for Interfaces

How does OJB support interfaces? I have a class that has a member variable
that is defined to an interface that I want to persist.

public class Person {
   Id id; // id is an interface
   String name;
}

The corresponding entry in the XML file looks like this:

   <class-descriptor
          class="Person"
          table="PERSON"
   >
      <field-descriptor
         name="name"
         column="NAME"
         jdbc-type="VARCHAR"
      />

     <field-descriptor
        name="id"
        column="ID"
        jdbc-type="INTEGER"
        conversion="Id2IntFieldConversion"
     />
  </class-descriptor>

When I comment out the 'id' in the xml file, everything works, but when I
have the 'id' reference in there, I get the following exception:

I'm getting the following exception when I try and persist this Person
object

rethrown as org.apache.ojb.broker.PersistenceBrokerException: Unable to
build ob
ject instance (MAYBE you don't have a constructor available):class Person:
Error setting field:id in object:Person
        at
org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl.buildWithRefle
ction(Unknown Source)

Thanks.

-Sherwin

Re: OJB Support for Interfaces

Posted by Sherwin Lu <sh...@hotmail.com>.
Hi all,

Please ignore my posting...I've solved my problem.

-Sherwin

----- Original Message ----- 
From: "Sherwin Lu" <sh...@hotmail.com>
To: "OJB Users List" <oj...@db.apache.org>
Sent: Wednesday, May 21, 2003 3:10 AM
Subject: OJB Support for Interfaces


> How does OJB support interfaces? I have a class that has a member variable
> that is defined to an interface that I want to persist.
>
> public class Person {
>    Id id; // id is an interface
>    String name;
> }
>
> The corresponding entry in the XML file looks like this:
>
>    <class-descriptor
>           class="Person"
>           table="PERSON"
>    >
>       <field-descriptor
>          name="name"
>          column="NAME"
>          jdbc-type="VARCHAR"
>       />
>
>      <field-descriptor
>         name="id"
>         column="ID"
>         jdbc-type="INTEGER"
>         conversion="Id2IntFieldConversion"
>      />
>   </class-descriptor>
>
> When I comment out the 'id' in the xml file, everything works, but when I
> have the 'id' reference in there, I get the following exception:
>
> I'm getting the following exception when I try and persist this Person
> object
>
> rethrown as org.apache.ojb.broker.PersistenceBrokerException: Unable to
> build ob
> ject instance (MAYBE you don't have a constructor available):class Person:
> Error setting field:id in object:Person
>         at
> org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl.buildWithRefle
> ction(Unknown Source)
>
> Thanks.
>
> -Sherwin
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>