geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Aaron Mulder" <ammul...@alumni.princeton.edu>
Subject Re: FindByPrimaryKey
Date Tue, 04 Apr 2006 17:28:56 GMT
I don't have time to dig through the spec at the moment, but I think
having a getter/setter is a spec requirement because I think the
container examines the getters and setters on the primary key class to
determine which CMP fields are primary key fields.  So if you don't
have any getters and setters, it's kind of like saying the primary key
consists of 0 columns.  I'm not sure that having a public instance
variable is sufficient in EJB 2.  But I'd have to consult the spec to
be sure.

There have got to be folks around who could tell you for sure --
perhaps Gianny or David B?

Thanks,
    Aaron

On 4/4/06, Olivier Voutat <olivier.voutat@gmail.com> wrote:
> A stack trace (can't give it to you right now because I'm at work and the
> application is at home).
>
> Think your idea of the set/get is nice, but it shouldn't be a problem
> because I have a constructor for the CarPK with an argument as you can see.
>
>
>  public String chassi;
>
>  public CarroPK() {}
>
>  public CarroPK(String chas) {
>           this.chassi = chas;
>  }
>
> Or it maybe the getChassi is needed ? My attribute chassi is public so I
> don't really need a getChassi, do I ?
>
>
>  <cmp-field><field-name>chassi</field-name></cmp-field>
>
> When I do the following:
>
>
> pk = (CarroPK)tempcar.getPrimaryKey;
> System.out.println(pk.chassi);
>
> It works. So what is going on (lol) ?
>
> I get a stack trace only at the moment of the findByPrimaryKey, the big
> problem is that this method is container managed, so can't see how it
> works...
>
> Best Regards,
> Olivier Voutat
>
>
>
> On 4/4/06, Aaron Mulder <ammulder@alumni.princeton.edu > wrote:
> > What's the actual problem?  When you call findByPrimaryKey, is it
> > returning nothing, or giving you a stack trace, or what?
> >
> > I think your primary key class is supposed to have getters and setters
> > for all the properties, with names matching the primary key fields on
> > the bean.  So it may be that you need a getChassi and setChassi on the
> > PK class to get it working.
> >
> > Thanks,
> >     Aaron
> >
> > P.S. Ever played Car Wars?  :)
> >
> > On 4/4/06, Olivier Voutat <olivier.voutat@gmail.com> wrote:
> > > I'm in trouble (again lol) with the findByPrimaryKey method.
> > >
> > > CarLocalHome localHomeCar = Locator.getCarLocalHome();
> > > CarLocal tempcar = null;
> > > try {
> > >             Iterator temp =
> > > localHomeCar.findBySituation("Avaliable").iterator();
> > >             CarPK pk = new CarPK();
> > >             while (temp.hasNext()) {
> > >                 tempcar = (CarLocal)temp.next();
> > >                 System.out.println("Primary Key " +
> > > tempcar.getPrimaryKey().toString());
> > >                 pk = (CarroPK)tempcar.getPrimaryKey();
> > > }
> > > System.out.println(pk.chassi);
> > > System.out.println("Everything works fine until here.");
> > >
> > >  CarLocal mycar = localHomeCar.findByPrimaryKey(new
> CarPK("CHASSSICODE"));
> > > //HERE I don't get to pick my ejbLocalObjet by the primary key.
> > >
> > > CarLocal mycar = localHomeCar.findByPrimaryKey (pk);
> > > //Tried this way too but no success
> > >
> -------------------------------------------------------------------------------------------------------------------------------
> > > // This is my CarPK class
> > > package br.cefetrn.olivier.entity;
> > >
> > > import java.io.Serializable;
> > >
> > > public class CarPK implements Serializable {
> > >
> > >     private static final long serialVersionUID = 1L;
> > >     public String chassi;
> > >
> > >     public CarroPK() {}
> > >
> > >     public CarroPK(String chas) {
> > >         this.chassi = chas;
> > >     }
> > >
> > >     public String toString() {
> > >         return chassi.toString ();
> > >     }
> > >
> > >     public int hashCode() {
> > >         return chassi.hashCode();
> > >     }
> > >
> > >     public boolean equals(Object car) {
> > >         return ((CarroPK)car).chassi.equals(chassi);
> > >     }
> > > }
> > >
> -------------------------------------------------------------------------------------------------------------------------------
> > > // This is my ejb-jar.xml code
> > >     <entity>
> > >         <ejb-name>Car</ejb-name>
> > >
> > >
> <local-home>br.cefetrn.olivier.entity.CarLocalHome</local-home>
> > >         <local>br.cefetrn.olivier.entity.CarLocal
> </local>
> > >
> > >
> <ejb-class>br.cefetrn.olivier.entity.CarBean</ejb-class>
> > >         <persistence-type>Container</persistence-type>
> > >         <prim-key-class>br.cefetrn.olivier.entity.CarPK
> </prim-key-class>
> > >     /////////////My PK class
> > >         <reentrant>false</reentrant>
> > >         <cmp-version>2.x</cmp-version>
> > >
> <abstract-schema-name>CARS</abstract-schema-name>
> > >
> > > <cmp-field><field-name>chassi</field-name></cmp-field>
> > >
> > >
> <cmp-field><field-name>manufacturer</field-name></cmp-field>
> > >
> > > <cmp-field><field-name>model</field-name></cmp-field>
> > >
> > > <cmp-field><field-name>plaque</field-name></cmp-field>
> > >
> <cmp-field><field-name>km</field-name></cmp-field>
> > >
> > > <cmp-field><field-name>color</field-name></cmp-field>
> > >
> > >
> <cmp-field><field-name>situation</field-name></cmp-field>
> > >
> > > <cmp-field><field-name>type</field-name></cmp-field>
> > >
> > > <cmp-field><field-name>price</field-name></cmp-field>
> > >         <resource-ref>
> > >             <res-ref-name>Fire</res-ref-name>
> > >                <res-type>javax.sql.DataSource</res-type>
> > >                <res-auth>Container</res-auth>
> > >
> > > <res-sharing-scope>Shareable</res-sharing-scope>
> > >         </resource-ref>
> > >     </entity>
> > >
> > > Does anyone knows what I'm doing wrong in this findByPrimaryKey ?
> > > Best Regards,
> > > --
> > > Olivier Voutat
> > > Rua Praia de Muriú, 9188
> > > Cep 59092-390 / Natal - RN
> > > Tel: (84) 3219-0427 Cel: (84) 9977-3917
> >
>
>
>
> --
> Olivier & Cidiane Voutat
>
> Rua Praia de Muriú, 9188
> Cep 59092-390 / Natal - RN
> Tel: (84) 3219-0427 Cel: (84) 9977-3917

Mime
View raw message