This behaviour can also be modified by changing the PersistentFieldClass 
in your OJB.properties file. The shipping default is to use
org.apache.ojb.broker.metadata.PersistentFieldPropertyImpl, which requires
JavaBeans conformant properties (getXXX/setXXX), but does not use reflection
(ie faster!)

However, if you want to use non-JavaBeans classes there are other
implementations: (from OJB.properties - not noted here is
PersistentFieldDynaBeanImpl)

# The PersistentFieldClass property defines the implementation class
# for PersistentField attributes used in the OJB MetaData layer.
# By default a attribute based Version using Reflection is selected.
# using this Class persistent attributes don't need getters and setters
# and don't have to be declared public or protected.
#
#PersistentFieldClass=org.apache.ojb.broker.metadata.PersistentFieldDefaultI
mpl
#
# There is also a high-speed version of this access strategy avalaible.
# The PersistentFieldMaxPerformanceImpl does not cooperate with
# an AccessController, but accesses the fields directly.
#PersistentFieldClass=org.apache.ojb.broker.metadata.PersistentFieldMaxPerfo
rmanceImpl
#
# The PersistentFieldPropertyImpl uses JavaBeans comformant calls only
# to access persistent attributes. No Reflection is needed.
# But for each attribute xxx there must be public getXxx() and setXxx()
methods.
#
PersistentFieldClass=org.apache.ojb.broker.metadata.PersistentFieldPropertyI
mpl
#

> -----Original Message-----
> From: Ryan Joseph [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, October 15, 2002 2:14 AM
> To: OJB Users List
> Subject: Re: Primary Keys
> 
> 
> Thanks Elliot, you got me on the right path. Got it working 
> now, and it
> makes sense frome here. Thanks for taking the time to help me out.
> 
> 
> On Tue, 2002-10-15 at 02:22, Eliot wrote:
> > I'm new to OJB but I think you need a getter and setter for each
> > attribute you want OJB to have access to.
> > 
> > On 15 Oct 2002 00:46:19 -0700
> > Ryan Joseph <[EMAIL PROTECTED]> wrote:
> > 
> > > Following the model in tutorial1 I created a my persistent
> > > object as follows:
> > > 
> > > public class OJBUser {
> > >   public  int id;
> > >   protected String FirstName;
> > >   protected String LastName;
> > >   protected String Email;
> > >   protected String UserLogin;
> > > }
> > > 
> > > In my DB, I the collumn is named "pkUserID" and thus I have
> > > mapped it in the repository_user.xml:
> > > 
> > >       <field-descriptor id="1"
> > >          name="id"
> > >          column="pkUserID"
> > >          jdbc-type="INTEGER"
> > >          primarykey="true"
> > >          autoincrement="true"
> > >       />
> > > 
> > > Now, I am getting this error when running the the example, as
> > > it seems the reflection code cannot find my id parameter in the
> > > object. Why?
> > > 
> > > 
> > > java.lang.reflect.InvocationTargetException
> > >   at
> > >   sun.reflect.NativeConstructorAccessorImpl.newInstance0(N
> > >   ative Method)
> > >   at
> > > sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeCo
> > > nstructorAccessorImpl.java:39)    at
> > > sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Dele
> > > gatingConstructorAccessorImpl.java:27)    at
> > > 
> java.lang.reflect.Constructor.newInstance(Constructor.ja
> va:274)       at
> > > org.apache.ojb.broker.metadata.PersistentFieldFactory.createPe
> > > rsistentField(Unknown Source)     at
> > > org.apache.ojb.broker.metadata.AttributeDescriptorBase.getPers
> > > istentField(Unknown Source)       at
> > > org.apache.ojb.broker.metadata.ClassDescriptor.getFieldDescrip
> > > torByName(Unknown Source) at
> > > org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl.selectC
> > > lassDescriptor(Unknown Source)    at
> > > org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl.readObj
> > > ectFrom(Unknown Source)   at
> > > org.apache.ojb.broker.accesslayer.RsIterator.getObjectFromResu
> > > ltSet(Unknown Source)     at
> > > org.apache.ojb.broker.accesslayer.RsIterator.next(Unknown
> > > Source)   at
> > > org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollec
> > > tionByQuery(Unknown Source)       at
> > > org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollec
> > > tionByQuery(Unknown Source)       at
> > > org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollec
> > > tionByQuery(Unknown Source)       at
> > > org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollec
> > > tionByQuery(Unknown Source)       at
> > > 
> com.tulip.data.OJBDataTool.GetUsersTest(OJBDataTool.java:42)  
> at com.tulip.data.OJBTest.main(OJBTest.java:24)
> > > Caused by: org.apache.ojb.broker.metadata.MetadataException:
> > > Can't find property id in com.tulip.data.OJBUser
> > >   at
> > > org.apache.ojb.broker.metadata.PersistentFieldPropertyImpl.fin
> > > dPropertyDescriptor(Unknown Source)       at
> > > org.apache.ojb.broker.metadata.PersistentFieldPropertyImpl.<in
> > > it>(Unknown Source)       ... 17 more
> > > rethrown as org.apache.ojb.broker.metadata.MetadataException:
> > > Error creating PersistentField: com.tulip.data.OJBUser, id
> > >   at
> > > org.apache.ojb.broker.metadata.PersistentFieldFactory.createPe
> > > rsistentField(Unknown Source)     at
> > > org.apache.ojb.broker.metadata.AttributeDescriptorBase.getPers
> > > istentField(Unknown Source)       at
> > > org.apache.ojb.broker.metadata.ClassDescriptor.getFieldDescrip
> > > torByName(Unknown Source) at
> > > org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl.selectC
> > > lassDescriptor(Unknown Source)    at
> > > org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl.readObj
> > > ectFrom(Unknown Source)   at
> > > org.apache.ojb.broker.accesslayer.RsIterator.getObjectFromResu
> > > ltSet(Unknown Source)     at
> > > org.apache.ojb.broker.accesslayer.RsIterator.next(Unknown
> > > Source)   at
> > > org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollec
> > > tionByQuery(Unknown Source)       at
> > > org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollec
> > > tionByQuery(Unknown Source)       at
> > > org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollec
> > > tionByQuery(Unknown Source)       at
> > > org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollec
> > > tionByQuery(Unknown Source)       at
> > > 
> com.tulip.data.OJBDataTool.GetUsersTest(OJBDataTool.java:42)  
> at com.tulip.data.OJBTest.main(OJBTest.java:24)
> > > 
> > > 
> > > 
> > > --
> > > To unsubscribe, e-mail:  
> > > <mailto:[EMAIL PROTECTED]> For additional
> > > commands, e-mail: <mailto:[EMAIL PROTECTED]>
> > > 
> > 
> > --
> > To unsubscribe, e-mail:   
> <mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail: 
> <mailto:[EMAIL PROTECTED]>
> > 
> 
> 
> --
> To unsubscribe, e-mail:   
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

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

Reply via email to