OK. Now I have a different exception. The object model is a recursive
composite pattern e.g. Account has a parent and children which are also
Accounts. Bank account is a specialization of Account with two extra fields.
<class-descriptor class="com.microremedies.pm.persist.BankAccount"
table="ACCOUNT">
<extent-class
class-ref="com.microremedies.pm.persist.BankAccountImpl"/>
</class-descriptor>
<class-descriptor class="com.microremedies.pm.persist.Account"
table="ACCOUNT">
<extent-class class-ref="com.microremedies.pm.persist.AccountImpl"/>
<extent-class class-ref="com.microremedies.pm.persist.BankAccount"/>
</class-descriptor>
<class-descriptor class="com.microremedies.pm.persist.AccountImpl"
table="ACCOUNT" proxy="dynamic">
<extent-class
class-ref="com.microremedies.pm.persist.BankAccountImpl"/>
<field-descriptor name="uid" column="uid" jdbc-type="INTEGER"
primarykey="true" autoincrement="true"/>
<field-descriptor name="name" column="name" jdbc-type="VARCHAR"/>
<field-descriptor name="number" column="number"
jdbc-type="INTEGER"/>
<field-descriptor name="typeName" column="typename"
jdbc-type="VARCHAR"/>
<field-descriptor name="parentAccountID" column="parentAccountID"
jdbc-type="INTEGER" access="anonymous"/>
<field-descriptor name="ojbConcreteClass" column="CLASS_NAME"
jdbc-type="VARCHAR"/>
<reference-descriptor name="parentAccount"
class-ref="com.microremedies.pm.persist.Account">
<foreignkey field-ref="parentAccountID"/>
</reference-descriptor>
<collection-descriptor name="subAccounts"
element-class-ref="com.microremedies.pm.persist.Account" auto-update="true">
<inverse-foreignkey field-ref="parentAccountID"/>
</collection-descriptor>
</class-descriptor>
<class-descriptor class="com.microremedies.pm.persist.BankAccountImpl"
table="ACCOUNT" proxy="dynamic">
<field-descriptor name="uid" column="uid" jdbc-type="INTEGER"
primarykey="true" autoincrement="true"/>
<field-descriptor name="name" column="name" jdbc-type="VARCHAR"/>
<field-descriptor name="number" column="number"
jdbc-type="INTEGER"/>
<field-descriptor name="typeName" column="typename"
jdbc-type="VARCHAR"/>
<field-descriptor name="parentAccountID" column="parentAccountID"
jdbc-type="INTEGER" access="anonymous"/>
<field-descriptor name="ojbConcreteClass" column="CLASS_NAME"
jdbc-type="VARCHAR"/>
<field-descriptor name="bankAccountNumber"
column="bankAccountNumber" jdbc-type="VARCHAR"/>
<field-descriptor name="nextCheckNumber" column="nextCheckNumber"
jdbc-type="INTEGER"/>
<reference-descriptor name="parentAccount"
class-ref="com.microremedies.pm.persist.Account">
<foreignkey field-ref="parentAccountID"/>
</reference-descriptor>
<collection-descriptor name="subAccounts"
element-class-ref="com.microremedies.pm.persist.Account" auto-update="true">
<inverse-foreignkey field-ref="parentAccountID"/>
</collection-descriptor>
</class-descriptor>
I can add and delete OK but the query:
QueryBySQL query = new QueryBySQL(BankAccount.class,"select * from
account");
Collection col = pb.getCollectionByQuery(query);
throws this stack trace:
[org.apache.ojb.broker.accesslayer.IndirectionHandler] ERROR: Method
invoking failed for method *getSubAccounts* on object null
org.apache.ojb.broker.OJBRuntimeException: Incorrect field reference
"parentAccountID" in
[EMAIL PROTECTED]
delete=false,cascade retrieve=true,cascade store=true,is lazy=false,class of
Items=interface com.microremedies.pm.persist.Account]
org.apache.ojb.broker.PersistenceBrokerException:
org.apache.ojb.broker.OJBRuntimeException: Incorrect field reference
"parentAccountID" in
[EMAIL PROTECTED]
delete=false,cascade retrieve=true,cascade store=true,is lazy=false,class of
Items=interface com.microremedies.pm.persist.Account]
at
org.apache.ojb.broker.accesslayer.IndirectionHandler.materializeSubject(Unkn
own Source)
at
org.apache.ojb.broker.accesslayer.IndirectionHandler.getRealSubject(Unknown
Source)
at
org.apache.ojb.broker.accesslayer.IndirectionHandler.invoke(Unknown Source)
at $Proxy0.getSubAccounts(Unknown Source)
at com.microremedies.pm.test.OJBTest.query(OJBTest.java:50)
at com.microremedies.pm.test.OJBTest.runtest(OJBTest.java:40)
at com.microremedies.pm.test.OJBTest.main(OJBTest.java:25)
Caused by: org.apache.ojb.broker.OJBRuntimeException: Incorrect field
reference "parentAccountID" in
[EMAIL PROTECTED]
delete=false,cascade retrieve=true,cascade store=true,is lazy=false,class of
Items=interface com.microremedies.pm.persist.Account]
at
org.apache.ojb.broker.metadata.ObjectReferenceDescriptor.getForeignKeyFieldD
escriptors(Unknown Source)
at
org.apache.ojb.broker.core.PersistenceBrokerImpl.getFKQuery1toN(Unknown
Source)
at
org.apache.ojb.broker.core.PersistenceBrokerImpl.getFKQuery(Unknown Source)
at
org.apache.ojb.broker.core.PersistenceBrokerImpl.retrieveCollection(Unknown
Source)
at
org.apache.ojb.broker.core.PersistenceBrokerImpl.retrieveCollections(Unknown
Source)
at
org.apache.ojb.broker.core.PersistenceBrokerImpl.getDBObject(Unknown Source)
at
org.apache.ojb.broker.core.PersistenceBrokerImpl.getObjectByIdentity(Unknown
Source)
at
org.apache.ojb.broker.core.DelegatingPersistenceBroker.getObjectByIdentity(U
nknown Source)
at
org.apache.ojb.broker.core.DelegatingPersistenceBroker.getObjectByIdentity(U
nknown Source)
... 7 more
org.apache.ojb.broker.PersistenceBrokerException: Error
invoking:getSubAccounts
at
org.apache.ojb.broker.accesslayer.IndirectionHandler.invoke(Unknown Source)
at $Proxy0.getSubAccounts(Unknown Source)
at com.microremedies.pm.test.OJBTest.query(OJBTest.java:50)
at com.microremedies.pm.test.OJBTest.runtest(OJBTest.java:40)
at com.microremedies.pm.test.OJBTest.main(OJBTest.java:25)
Caused by: org.apache.ojb.broker.PersistenceBrokerException:
org.apache.ojb.broker.OJBRuntimeException: Incorrect field reference
"parentAccountID" in
[EMAIL PROTECTED]
delete=false,cascade retrieve=true,cascade store=true,is lazy=false,class of
Items=interface com.microremedies.pm.persist.Account]
at
org.apache.ojb.broker.accesslayer.IndirectionHandler.materializeSubject(Unkn
own Source)
at
org.apache.ojb.broker.accesslayer.IndirectionHandler.getRealSubject(Unknown
Source)
... 5 more
Caused by: org.apache.ojb.broker.OJBRuntimeException: Incorrect field
reference "parentAccountID" in
[EMAIL PROTECTED]
delete=false,cascade retrieve=true,cascade store=true,is lazy=false,class of
Items=interface com.microremedies.pm.persist.Account]
at
org.apache.ojb.broker.metadata.ObjectReferenceDescriptor.getForeignKeyFieldD
escriptors(Unknown Source)
at
org.apache.ojb.broker.core.PersistenceBrokerImpl.getFKQuery1toN(Unknown
Source)
at
org.apache.ojb.broker.core.PersistenceBrokerImpl.getFKQuery(Unknown Source)
at
org.apache.ojb.broker.core.PersistenceBrokerImpl.retrieveCollection(Unknown
Source)
at
org.apache.ojb.broker.core.PersistenceBrokerImpl.retrieveCollections(Unknown
Source)
at
org.apache.ojb.broker.core.PersistenceBrokerImpl.getDBObject(Unknown Source)
at
org.apache.ojb.broker.core.PersistenceBrokerImpl.getObjectByIdentity(Unknown
Source)
at
org.apache.ojb.broker.core.DelegatingPersistenceBroker.getObjectByIdentity(U
nknown Source)
at
org.apache.ojb.broker.core.DelegatingPersistenceBroker.getObjectByIdentity(U
nknown Source)
... 7 more
Exception in thread "main"
-Ken
> -----Original Message-----
> From: Gelhar, Wallace Joseph [mailto:[EMAIL PROTECTED]
> Sent: Monday, November 17, 2003 9:38 AM
> To: OJB Users List
> Subject: RE: dynamic proxy HOWTO+
>
>
> Hi Ken,
>
> Sorry, I wasn't very specific. You are correct in that the
> implementation class-descriptor should be declared as an extent of the
> interface class-descriptor. The interface class-descriptor does not
> require any field attributes to be declared for it.
>
> Wally
>
> -----Original Message-----
> From: Ken Brewer [mailto:[EMAIL PROTECTED]
> Sent: Monday, November 17, 2003 8:29 AM
> To: OJB Users List; [EMAIL PROTECTED]
> Subject: RE: dynamic proxy HOWTO+
>
>
> Thanks. Do you mean that the interface should be an extent-class inside
> the implementation class-descriptor? It seems that it should be the
> other way around e.g. the implementation class would be an extent-class
> inside the interface class-descriptor?
>
> > -----Original Message-----
> > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> > Sent: Monday, November 17, 2003 2:22 AM
> > To: OJB Users List
> > Subject: Re: dynamic proxy HOWTO+
> >
> >
> > Hi Ken,
> >
> > Ken Brewer wrote:
> > > I just started using OJB and so far so good. I'm confused about
> > the dynamic
> > > proxies. Previous to OJB, my object model used inheritance but no
> > > interfaces. Because I want lazy loading, I created an interface
> > for nearly
> > > every class. I simply named these interfaces 'I + classname'
> > e.g. Account
> > > now has an interface IAccount. I noticed that I had to change
> > my cast from
> > > the class to the interface when retrieving collection elements.
> > >
> > > 1. My application is substantially complete and has many
> > references to the
> > > class names e.g. Account. it seems I should have used the scheme
> > > Account(interface) & AccountImpl(class) in order to avoid breaking
> > > my application code references to Account, RIGHT?
> >
> > The OJB proxy mechanism provides a wrapper implementation for the
> > concrete AccountImpl. This wrapper implementation (which does the lazy
> > load) implements the interface Account.
> > So in you business object you always have to use the interface Account
>
> > to work safely with proxies. Of course it makes sense to have
> > convenient naming convention to differentiate between interfaces and
> > proxies. But OJB does not force you to any special names.
> >
> > > 2. When casting objects from a collection, should I cast to the
> > class name
> > > or proxy interface name?
> >
> > When using proxies always use the interface name. see explanation
> > above.
> >
> > > 3. Must I include the full hierarchy, including interfaces, in my
> > > repository.xml even though the interfaces are for dynamic proxies
> > > only?
> >
> > You must include at least one extent definition for the interface to
> > allow OJB to perform queries against that interface type. But you do
> > not have to declare the complete hierarchy.
> >
> > > 4. In the repository.xml, it seems that all superclass elements must
>
> > > be duplicated in each subclass? Is that correct?
> >
> > That depends on the mapping strategy. See
> > http://db.apache.org/ojb/tutorial3.html#mapping%20inheritance%20hi
> erarchies
> for details.
>
>
> cu,
> Thomas
> >
> > Thanks,
> >
> > -ken
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]