There's a problem with using access="anonymous" in case we use it in field-descriptors which are also primery keys. It seems that when OJB tries to get the value from that field to construct an identity, it returns null (it looks it some kind of cache for anonymous fields I cannot understand what it does).

Have you found this problem?


From: "Daniel Perry" <[EMAIL PROTECTED]>
Reply-To: "OJB Users List" <[EMAIL PROTECTED]>
To: "OJB Users List" <[EMAIL PROTECTED]>
Subject: RE: Reference proxies & Interfaces
Date: Fri, 21 May 2004 11:33:15 +0100

> d. You say that I should use an 'extra' attribute in class 'CityVO' to
> represent the 'foreign key' in the table. But, in my opinion, this breaks
> with OO design, as I am using 'relational concepts' instead of 'OO
> concepts'. This is one of the problems of the 'impedance mismatch' and I
> think the OO way to solve it is using OO design the way I suggested.


I kind of agree with you here! However OJB supports anonymous fields -
columns that exist in the database, but have no field in the associated
class, and these allow you to do what you are doing.

    <field-descriptor
        id="3"
        name="state::codState"
        column="ID_STATE"
        jdbc-type="INTEGER"
        access="anonymous"/>

> b. You say I don't have to instantiate the variable 'state' inside the
> constructor of class 'CityVO'. But if I don't put that code in the
> constructor I get the following exception:


I dont understand what is causing this. What version of OJB are you using?

Maybe the anonymous field above is causing the problem? Not sure what OJB
does if access="anonymous" is not set, and there is no field in the class.
Also, you might like to change the name, as it isnt a valid java variable
name.

Daniel.

> -----Original Message-----
> From: Enrique Medina [mailto:[EMAIL PROTECTED]
> Sent: 20 May 2004 19:00
> To: [EMAIL PROTECTED]
> Subject: RE: Reference proxies & Interfaces
>
>
> Thanks very much for your comments. Just a pair of comments:
>
> b. You say I don't have to instantiate the variable 'state' inside the
> constructor of class 'CityVO'. But if I don't put that code in the
> constructor I get the following exception:
>
> java.lang.InstantiationException: StateProxy
> at
> org.apache.ojb.broker.metadata.fieldaccess.AbstractPersistentField
> .setNestedObject(AbstractPersistentField.java:329)
> at
> org.apache.ojb.broker.metadata.fieldaccess.AbstractPersistentField
> .set(AbstractPersistentField.java:100)
> at
> org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl.buildWithRe
> flection(RowReaderDefaultImpl.java:260)
> at
> org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl.readObjectF
> rom(RowReaderDefaultImpl.java:77)
> at
> org.apache.ojb.broker.accesslayer.RsIterator.getObjectFromResultSe
> t(RsIterator.java:488)
> at
> org.apache.ojb.broker.accesslayer.RsIterator.next(RsIterator.java:288)
> at
> org.apache.ojb.broker.accesslayer.PagingIterator.next(PagingIterat
> or.java:187)
> at
> org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQue
> ry(QueryReferenceBroker.java:171)
> at
> org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQue
> ry(QueryReferenceBroker.java:211)
> at
> org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQue
> ry(QueryReferenceBroker.java:223)
> at
> org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQu
> ery(PersistenceBrokerImpl.java:1205)
> at
> org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollecti
> onByQuery(DelegatingPersistenceBroker.java:331)
> at
> org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollecti
> onByQuery(DelegatingPersistenceBroker.java:331)
>
> d. You say that I should use an 'extra' attribute in class 'CityVO' to
> represent the 'foreign key' in the table. But, in my opinion, this breaks
> with OO design, as I am using 'relational concepts' instead of 'OO
> concepts'. This is one of the problems of the 'impedance mismatch' and I
> think the OO way to solve it is using OO design the way I suggested.
>
> Regards,
> Enrique Medina.
>
>
> >From: "Daniel Perry" <[EMAIL PROTECTED]>
> >Reply-To: "OJB Users List" <[EMAIL PROTECTED]>
> >To: "OJB Users List" <[EMAIL PROTECTED]>
> >Subject: RE: Reference proxies & Interfaces
> >Date: Thu, 20 May 2004 18:43:37 +0100
> >
> >I ended up spending time trying to understand proxies... confusing stuff
> >when you start out with ojb... these days it's making a little
> more sense
> >:)
> >
> >a. yes, it has to be of type StateProxy (the interface) as ojb
> will try to
> >instanciate it with a proxy object that implements the interface. If you
> >use a StateVO, ojb cant just point it to a proxy.
> >
> >b. I didnt think so. I'm pretty sure my code was not doing this, and was
> >working fine.
> >
> >c. This is correct. In fact you dont need the CityProxy
> interface at all.
> >Early on i got it into my head that i needed interfaces for collection
> >proxies like this. It was only the other day that i realised otherwise!
> >
> >d. dont quite understand the code here... i would use fkStateId and then
> >have "private int fkStateId;" in CityVO +interface.
> >
> >To be honest, i barely ever use reference proxies any more as i
> found that
> >they didnt have much effect on performance of my apps, and i had to use
> >interfaces everywhere. I almost always proxy collections
> though, as these
> >do make a big difference.
> >
> >Daniel.
> >
> > > -----Original Message-----
> > > From: Enrique Medina [mailto:[EMAIL PROTECTED]
> > > Sent: 20 May 2004 18:25
> > > To: [EMAIL PROTECTED]
> > > Subject: Reference proxies & Interfaces
> > >
> > >
> > > This is just a confirmation question about using reference
> > > proxies in OJB. I
> > > have been using them in all my applications, but I would like
> to confirm
> > > that I am making a good use of them.
> > >
> > > So my way of using reference proxies is:
> > >
> > > 1) Let's consider two business entities: state and city. So I have:
> > >
> > > public interface StateProxy
> > > {
> > > public Integer getCodState();
> > > public String getDescState();
> > > public Collection getCities();
> > >
> > > public void setCodState(Integer state);
> > > public void setDescState(String description);
> > > public void setCities(Collection cities);
> > > }
> > >
> > > public class StateVO implements StateProxy, Serializable
> > > {
> > > private Integer codState;
> > > private String descState;
> > >
> > > private Collection cities;
> > >
> > > public StateVO()
> > > {
> > > }
> > >
> > > // Getters/Setters ....
> > > }
> > >
> > > public interface CityProxy
> > > {
> > > public Integer getCodCity();
> > > public String getDescCity();
> > > public StateProxy getState();
> > >
> > > public void setCodCity(Integer city);
> > > public void setDescCity(String description);
> > > public void setState(StateProxy state);
> > > }
> > >
> > > public class CityVO implements CityProxy, Serializable
> > > {
> > > private Integer codCity;
> > > private String descCity;
> > >
> > > private StateProxy state;
> > >
> > > public CityVO()
> > > {
> > > state = new StateVO();
> > > }
> > >
> > > // Getters/Setters ....
> > > }
> > >
> > > 2) Do the mapping in repository-user.xml:
> > >
> > > <class-descriptor
> > > class="StateVO"
> > > table="TBL_STATE"
> > > >
> > >
> > > <field-descriptor
> > > id="1"
> > > name="codState"
> > > column="ID_STATE"
> > > jdbc-type="INTEGER"
> > > primarykey="true" />
> > >
> > > <field-descriptor
> > > id="2"
> > > name="descState"
> > > column="DESC_STATE"
> > > jdbc-type="VARCHAR" />
> > >
> > > <collection-descriptor
> > > name="cities"
> > > element-class-ref="CityVO"
> > > proxy="true">
> > >
> > > <inverse-foreignkey field-id-ref="3" />
> > >
> > > </collection-descriptor>
> > >
> > > </class-descriptor>
> > >
> > > <class-descriptor
> > > class="CityVO"
> > > table="TBL_CITY"
> > > >
> > >
> > > <field-descriptor
> > > id="1"
> > > name="codCity"
> > > column="ID_CITY"
> > > jdbc-type="INTEGER"
> > > primarykey="true" />
> > >
> > > <field-descriptor
> > > id="2"
> > > name="descCity"
> > > column="DESC_CITY"
> > > jdbc-type="VARCHAR" />
> > >
> > > <field-descriptor
> > > id="3"
> > > name="state::codState"
> > > column="ID_STATE"
> > > jdbc-type="INTEGER" />
> > >
> > > <reference-descriptor
> > > name="state"
> > > class-ref="StateVO"
> > > proxy="true">
> > >
> > > <foreignkey field-id-ref="3" />
> > >
> > > </reference-descriptor>
> > >
> > > </class-descriptor>
> > >
> > > And my questions are the following:
> > >
> > > a) I declare the variable 'state' in class 'CityVO' as being of type
> > > 'StateProxy' (the interface). If not, I get errors from OJB
> indicating
> >it
> > > can't obtain a getter/setter for the 'Proxy' object (I suppose it
> > > tries to
> > > obtain a getter/setter for the interface, not for the
> > > implementacion class).
> > > Is this the right behaviour?
> > >
> > > b) I have to instantiate the variable 'state' in class 'CityVO'
> > > inside the
> > > default constructor, because if not, OJB throws an exception saying it
> > > cannot instantiate 'StateProxy'. I suppose this must be correct.
> > >
> > > c) With the collection variable 'cities' in class 'StateVO',
> > > there's no need
> > > to instantiate it on the constructor, as OJB knows how to instantiate
> >any
> > > collection. Am I right?
> > >
> > > d) Do you think is correct to map the 'foreign key' using the variable
> > > 'state' defined in class 'CityVO' in the way 'state::codState' in the
> > > class-descriptor for 'CityVO'?
> > >
> > > I would welcome any suggestions, critics and comments from anyone
> > > that has
> > > worked with reference proxies and interfaces with OJB.
> > >
> > > Thanks in advance,
> > > Enrique Medina.
> > >
> > > _________________________________________________________________
> > > �D�nde se esconden [EMAIL PROTECTED] [EMAIL PROTECTED] Encuentra miles de perfiles en
> > > MSN Amor &
> > > Amistad. http://match.msn.es/
> > >
> > >
> > > ---------------------------------------------------------------------
> > > 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]
> >
>
> _________________________________________________________________
> �Est�s pensando en cambiar de coche? Todas los modelos de serie y
> extras en
> MSN Motor. http://motor.msn.es/researchcentre/
>
>
> ---------------------------------------------------------------------
> 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]


_________________________________________________________________
Correos m�s divertidos con fotos y textos incre�bles en MSN Premium. Pru�balo gratis dos meses. http://join.msn.com/?pgmarket=es-es&page=features/richmail&XAPID=1684&DI=1055&HL=TAG6OPENINGTEXT_MSNPREMIUM_VIRUS



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



Reply via email to