Hi!

Interesting that the error doesn't occur when attribute is ArrayList and
set/get works with Collection (let's see: ArrayList is an instance of
Collection, so... this works).

But if I have a setter method that work with items (setMyCollection( int
index, MySecondBean bean) ) - stop working.

AFAIK (and I'm making extensible use of OJB), using ArrayList for Set/Get
Collections is fine. The problem is with settter that work with individual
items (that causes NullPointerException). Appear that OJB is not reconizing
signature (or is just looking for a method setMyCollection( ArrayList ) -
not for superclasses (Collection, in this case) ).

Excuse-me if phrases above has too much parentesis, I can't avoid... ;-)

Thanks by your tips... I'll try to work with ArrayList always (as suggested
by S.Thompson)...


Edson Richter

----- Original Message -----
From: "Thomas Mahler" <[EMAIL PROTECTED]>
To: "OJB Users List" <[EMAIL PROTECTED]>
Sent: Tuesday, October 08, 2002 2:32 PM
Subject: Re: Trouble with Getter/Setter - using 0.9.7 and olders!


> Hi,
>
> The problem IMO is that the attribute
> private ArrayList myCollection
> and the getter
> public Collection getMyCollection( )
> and the setter
> public void setMyCollection( Collection myNewCollection )
> do not form a Java beans compliant attribute/getter/setter trio, as they
> are of different types.
> Java will not be able to detect them as matching !
>
> you can:
> 1. fix this by using proper typing
> 2. define a BeanInfo class that declares which methods are to be used
> for accessing the myCollection attribute
> 3. tell OJB to not use Java beans compliant calls to access attributes
> but use direct reflection access. You can do so by setting the
> PersistentField Implementation class in OJB.properties.
>
> cheers,
> Thomas
>
> Edson Carlos Ericksson Richter wrote:
> > Hi!
> > This is a very long e-mail. Excuse-me sending as is, but is the only way
to
> > explain this bug.
> >
> > I think I already reported this issue, but since today I had some
extended
> > tests, I'll report results:
> >
> > 1) I've created a bean called MyFirstBean with properties
> >
> > public class MyFirstBean implements Serializable {
> >   private int beanId;
> >   private String beanName;
> >   private ArrayList myCollection = new ArrayList( );
> >
> >   public void setBeanId( int newBeanId ) {
> >     beanId = newBeanId;
> >   }
> >   public int getBeanId( ) {
> >     return beanId;
> >   }
> >   public void setBeanName( String newBeanName ) {
> >     beanName = newBeanName;
> >   }
> >   public String getBeanName( ) {
> >     return beanName;
> >   }
> >   public void setMyCollection( int index, MySecondBean bean ) {
> >     if( index > myCollection.size( ) )
> >       myCollection.add( bean );
> >     else
> >       myCollection.set( index, bean );
> >   }
> >   public MySecondBean getMyCollection( int index ) {
> >     return ( MySecondBean )myCollection.get( index );
> >   }
> >   public Collection getMyCollection( ) {
> >     return myCollection;
> >   }
> >   public void setMyCollection( Collection myNewCollection ) {
> >     myCollection.clear( );
> >     myCollection.addAll( myNewCollection );
> >   }
> > }
> >
> > Ok, define the main class (MySecondBean no makes difference here), and
> > creating a repository.xml that makes relationships between two tables to
> > work by a collection descriptor, if I maintain the method
setMyCollection
> > (int, bean), I get (mail continues after stacktrace):
> >
> > java.lang.NullPointerException
> >         at
> >
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.retrieveCollection(Unkn
> > own Source)
> >         at
> >
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.retrieveCollections(Unk
> > nown Source)
> >         at
> >
org.apache.ojb.broker.accesslayer.RsIterator.getObjectFromResultSet(Unknown
> > Source)
> > [org.apache.ojb.broker.ta.PersistenceBrokerFactoryDefaultImpl] INFO:
Already
> > created persistence broker instances: 1
> > [ConfigurableFactory] INFO: ConfigurableFactory called to serve a class
> > org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl instance
> > [ConfigurableFactory] INFO: ConfigurableFactory called to serve a class
> > org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl instance
> > [ConfigurableFactory] INFO: ConfigurableFactory called to serve a class
> > org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl instance
> > [ConfigurableFactory] INFO: ConfigurableFactory called to serve a class
> > org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl instance
> > [ConfigurableFactory] INFO: ConfigurableFactory called to serve a class
> > org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl instance
> >         at org.apache.ojb.broker.accesslayer.RsIterator.next(Unknown
Source)
> >         at
> >
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollectionByQuery(Un
> > known Source)
> >         at
> >
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollectionByQuery(Un
> > known Source)
> >         at
> >
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollectionByQuery(Un
> > known Source)[org.apache.ojb.broker.accesslayer.RsIterator] ERROR: null
> >         at
> >
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollectionByQuery(Un
> > known Source)
> >         at
> >
br.com.everest.composer.persistence.TestePersistente.<init>(TestePersistente
> > .java:39)
> >         at
> >
br.com.everest.composer.persistence.TestePersistente.main(TestePersistente.j
> > ava:63)
> > java.lang.NullPointerException
> >         at
> >
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.retrieveCollection(Unkn
> > own Source)
> >         at
> >
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.retrieveCollections(Unk
> > nown Source)
> >         at
> >
org.apache.ojb.broker.accesslayer.RsIterator.getObjectFromResultSet(Unknown
> > Source)
> >         at org.apache.ojb.broker.accesslayer.RsIterator.next(Unknown
Source)
> >         at
> >
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollectionByQuery(Un
> > known Source)
> >         at
> >
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollectionByQuery(Un
> > known Source)
> >         at
> >
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollectionByQuery(Un
> > known Source)
> >         at
> >
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollectionByQuery(Un
> > known Source)Erro: null
> >         at
> >
br.com.everest.composer.persistence.TestePersistente.<init>(TestePersistente
> > .java:39)
> >         at
> >
br.com.everest.composer.persistence.TestePersistente.main(TestePersistente.j
> > ava:63)
> > java.util.NoSuchElementException
> >         at org.apache.ojb.broker.accesslayer.RsIterator.next(Unknown
Source)
> >         at
> >
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollectionByQuery(Un
> > known Source)
> >         at
> >
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollectionByQuery(Un
> > known Source)
> >         at
> >
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollectionByQuery(Un
> > known Source)
> >         at
> >
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollectionByQuery(Un
> > known Source)
> >         at
> >
br.com.everest.composer.persistence.TestePersistente.<init>(TestePersistente
> > .java:39)
> >         at
> >
br.com.everest.composer.persistence.TestePersistente.main(TestePersistente.j
> > ava:63)
> >
> >
> > and, if I remove this method, maintaining only setMyCollection
(Collection),
> > all works fine.
> >
> > Since the bean is correct (and compatible) with JavaBean spec, someone
can
> > fix this? I really tryied to do this, but OJB is above my compreension
(I
> > don't have domain over XML/Reflections APIs - and I get lost in OJB
> > sources).
> >
> > Thanks,
> >
> > Edson Richter
> >
> >
> >
> > ---
> > Email foi verificado quanto a exist�ncia de virus antes de seu envio, e
n�o
> > h� virus.
> > Checked by AVG anti-virus system (http://www.grisoft.com).
> > Version: 6.0.394 / Virus Database: 224 - Release Date: 03/10/2002
> >
> >
> >
> > --
> > 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]>
>
>


---
Email foi verificado quanto a exist�ncia de virus antes de seu envio, e n�o
h� virus.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.394 / Virus Database: 224 - Release Date: 03/10/2002



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

Reply via email to