geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Olivier Voutat" <olivier.vou...@gmail.com>
Subject FindByPrimaryKey
Date Tue, 04 Apr 2006 16:00:30 GMT
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