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 16:23:13 GMT
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

Mime
View raw message