> >
> > Collection artikels = new ArrayList();
> > artikels.add(artikel);
> ^^^^^^^^ is this your product created above?
Yes that is the Product! (I "translated" the Source from German to
English and forgot some parts, sorry)
> I always used this way (adapted to your example):
>
[quoted text clipped - 6 lines]
>
> -marek
first of all thanks for help
If I use this Code in a SessionBean (means I use the Local -
Interfaces) it works. But I get an Exception if I try to get the
Collection filled with Artikels.
Collection artikels = artikelGruppe.getArtikel(); // throws an
Exception
Here some more Code:
public abstract class ArtikelBean implements EntityBean {
protected EntityContext ctx;
public abstract Integer getArtid();
public abstract void setArtid(Integer id);
public abstract String getBezeichnung();
public abstract void setBezeichnung(String name);
public abstract Collection getArtikelGruppe();
public abstract void setArtikelGruppe(Collection artgruppen);
public void setEntityContext (EntityContext ctx) {
this.ctx = ctx;
}
....
}
public interface Artikel extends EJBObject {
public Integer getArtid() throws RemoteException;
public void setArtid(Integer id) throws RemoteException;
public String getBezeichnung() throws RemoteException;
public void setBezeichnung(String bez) throws RemoteException;
public Collection getArtikelGruppe() throws RemoteException;
public void setArtikelGruppe(Collection artgruppen) throws
RemoteException;
}
The ejb-jar.xml
<?xml version="1.0"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise
JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<enterprise-beans>
<entity>
<ejb-name>Artikel</ejb-name>
<home>satzmedia.sGrid.app.model.ArtikelHome</home>
<remote>satzmedia.sGrid.app.model.Artikel</remote>
<local-home>satzmedia.sGrid.app.model.ArtikelLocalHome</local-home>
<local>satzmedia.sGrid.app.model.ArtikelLocal</local>
<ejb-class>satzmedia.sGrid.app.model.ArtikelBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Integer</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>ArtikelBean </abstract-schema-name>
<cmp-field><field-name>artid</field-name></cmp-field>
<cmp-field><field-name>bezeichnung</field-name></cmp-field>
<primkey-field>artid</primkey-field>
<query>
<query-method>
<method-name>findByBezeichnung</method-name>
<method-params>
<method-param>java.lang.String</method-param>
</method-params>
</query-method>
<ejb-ql>
<![CDATA[SELECT OBJECT(a) FROM ArtikelBean AS a where
a.bezeichnung = ?1]]>
</ejb-ql>
</query>
</entity>
<entity>
<ejb-name>ArtikelGruppe</ejb-name>
<home>satzmedia.sGrid.app.model.ArtikelGruppeHome</home>
<remote>satzmedia.sGrid.app.model.ArtikelGruppe</remote>
<local-home>satzmedia.sGrid.app.model.ArtikelGruppeLocalHome</local-home>
<local>satzmedia.sGrid.app.model.ArtikelGruppeLocal</local>
<ejb-class>satzmedia.sGrid.app.model.ArtikelGruppeBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Integer</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>ArtikelGruppeBean</abstract-schema-name>
<cmp-field><field-name>id</field-name></cmp-field>
<cmp-field><field-name>bezeichnung</field-name></cmp-field>
<primkey-field>id</primkey-field>
<query>
<query-method>
<method-name>findByBezeichnung</method-name>
<method-params>
<method-param>java.lang.String</method-param>
</method-params>
</query-method>
<ejb-ql>
<![CDATA[SELECT OBJECT(a) FROM ArtikelGruppeBean AS a
where a.bezeichnung = ?1]]>
</ejb-ql>
</query>
</entity>
</enterprise-beans>
<relationships>
<ejb-relation>
<ejb-relation-name>Artikel-ArtikelGruppe</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>
Artikel haben ArtikelGruppen
</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<relationship-role-source>
<ejb-name>Artikel</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>ArtikelGruppe</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>
Artikelgruppen haben Artikel
</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<relationship-role-source>
<ejb-name>ArtikelGruppe</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>Artikel</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>
</relationships>
</ejb-jar
Marek Lange - 22 Oct 2003 19:45 GMT
ralf sczepan schrieb:
> If I use this Code in a SessionBean (means I use the Local -
> Interfaces) it works. But I get an Exception if I try to get the
> Collection filled with Artikels.
I saw your posting in d.c.l.j. See my comments on bean design please.
> public abstract class ArtikelBean implements EntityBean {
> protected EntityContext ctx;
[quoted text clipped - 8 lines]
> this.ctx = ctx;
> }
Looks good.
> public interface Artikel extends EJBObject {
> public Integer getArtid() throws RemoteException;
[quoted text clipped - 6 lines]
> RemoteException;
> }
I assume from this that you are using a remote interface for your Entity
Beans? Please try to change to local interfaces. Accessing an entity
remotely is poor design.
> The ejb-jar.xml
Nothing seems to be wrong in your descriptor. I can't explain the
ClassCastException so far.
-marek