Return-Path: Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: (qmail 54671 invoked from network); 8 Mar 2009 18:50:49 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 8 Mar 2009 18:50:49 -0000 Received: (qmail 7819 invoked by uid 500); 8 Mar 2009 18:50:49 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 7796 invoked by uid 500); 8 Mar 2009 18:50:49 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 7785 invoked by uid 99); 8 Mar 2009 18:50:48 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 08 Mar 2009 11:50:48 -0700 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=SPF_HELO_PASS,SPF_PASS,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of lists+1214986160035-208411@n2.nabble.com designates 216.139.236.158 as permitted sender) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 08 Mar 2009 18:50:41 +0000 Received: from tervel.nabble.com ([192.168.236.150]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1LgO4p-0006gn-WC for users@openjpa.apache.org; Sun, 08 Mar 2009 11:50:20 -0700 Message-ID: <1236538219989-2445629.post@n2.nabble.com> Date: Sun, 8 Mar 2009 11:50:19 -0700 (PDT) From: Pinaki Poddar To: users@openjpa.apache.org Subject: Re: ManagedInterfaces In-Reply-To: <20090306213849.33F93816024@nike.apache.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Nabble-From: ppoddar@apache.org References: <20090306213849.33F93816024@nike.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Hi, > 3. we use OpenJPAEntityManager.createInstance(Class) to instantiate objects This method will create a class *dynamically* which implements the given interface.=20 As the stacktrace shows, it has created a class named 'de.huk.vtp.selektionen.bo.ParameterListeAtomar$1841851848openjpaimpl'. But this dynamically generated class does not know what do when some calls its fetchDomainAssociation() method on it and simply will throw exception. It only knows how to behave for its bean-style get/set methods. So, for this use case where you not only use ManagedInterface but also have implemented these interfaces, you should instantiate your implemented class directly i.e. ParameterListeAtomar pc =3D new ParameterListeAtomarImpl(...); You can continue using the interface for find() or query such as ParameterListeAtomar pc =3D em.find(ParameterListeAtomar.class, someId); This should return you an instance of ParameterListeAtomarImpl which has the correct implementation of fetchDomainAssociation(). Annette Scherer wrote: >=20 > Hello, > =20 > we have several problems using OpenJPA with managed interfaces. > I try to explain: > =20 > preconditions > 1. we use the model below. Each interface is implemented by a class with > postfix Impl > 2. we continuously use ManagedInterfaces > 3. we use OpenJPAEntityManager.createInstance(Class) to instantiate > objects > =20 > =20 > problems > 1. when reading a kategorie object with openJPAEm.find(Kategorie.class, > String name) we get an openjpa object like this, which differs from our > implementations. > =20 >=20 > =20 > When trying to call a method of one of our implementations (for example > fetchDomainAssociation on ParameterListeAtomarImpl, we get this exception= : > [05.03.09 15:34:29:796 CET] 00000020 SystemErr R > java.lang.UnsupportedOperationException > [05.03.09 15:34:29:812 CET] 00000020 SystemErr R at > de.huk.vtp.selektionen.bo.ParameterListeAtomar$1841851848openjpaimpl.fetc= hDo > mainAssociation(Unknown Source) > =20 > How can we avoid this problem? It is a killer argument for using JPA in > our > applications, for using interfaces is a corporation wide paradigma. > =20 > =20 > =20 > 2. another problem is the use of inheritance. With annotations we used fo= r > Parameter, ParameterAtomar for example, we receive this exeption: > [04.03.09 14:17:47:004 CET] 00000021 SystemOut O [04 M=C3=A4r 2009 14:17:= 46] > DEBUG [LifecycleImpl.java:259 -- phase] - afterPhase(RESTORE_VIEW > 1,com.icesoft.faces.context.BridgeFacesContext@60ae60ae) threw exception: > > org.apache.openjpa.persistence.ArgumentException: Discriminator value > "ATOMAR" is used for two different classes in the same inheritance tree: > "interface de.huk.vtp.selektionen.bo.ParameterAtomar", > "de.huk.vtp.selektionen.bo.ParameterAtomar" Discriminator value "ATOMAR" > is > used for two different classes in the same inheritance tree: "interface > de.huk.vtp.selektionen.bo.ParameterAtomar", > "de.huk.vtp.selektionen.bo.ParameterAtomar" >=20 > > org.apache.openjpa.persistence.ArgumentException: Discriminator value > "ATOMAR" is used for two different classes in the same inheritance tree: > "interface de.huk.vtp.selektionen.bo.ParameterAtomar", > "de.huk.vtp.selektionen.bo.ParameterAtomar" >=20 > at > org.apache.openjpa.jdbc.meta.strats.ValueMapDiscriminatorStrategy.mapDisc= rim > inatorValue(ValueMapDiscriminatorStrategy.java:116) >=20 > Thanks for you=C2=B4r advice >=20 > Annette Scherer >=20 > =20 > =20 > =20 > =20 > =20 > =20 > =20 > extract of our model: > =20 > @Entity > @Table(name=3D"TAKATEGORIE") > @ManagedInterface > public interface Kategorie extends Serializable{ > @Id > @Column(name=3D"NAME", length=3D50) > public String getName(); > public void setName(String newName); > =20 > @OneToMany(fetch=3DFetchType.EAGER, cascade=3D{CascadeType.PERSIST}) > public java.util.List getTypListe(); > public void setTypListe(java.util.List newTypListe); > =20 > public void addToTypListe(Typ o); > public void removeFromTypListe(Typ o); > } > =20 > =20 > @Entity > @Table(name=3D"TATYP") > @ManagedInterface > public interface Typ extends Serializable { > @Id > @Column(name=3D"SELEKTIONSNUMMER", length=3D4) > public String getSelectionID(); > public void setSelectionID(String newOperationId); > =20 > @Column(name=3D"NAME", length=3D60) > public String getName(); > public void setName(String newName); > =20 > @OneToMany(fetch=3DFetchType.EAGER, cascade=3D{CascadeType.PERSIST}) > public java.util.List getParameterListe(); > public void setParameterListe(java.util.List > newParameterListe); > =20 > public void addToParameterListe(Parameter o); > public void removeFromParameterListe(Parameter o); > } > =20 > =20 > @Entity > @Table(name=3D"TAPARAMETER") > @Inheritance(strategy=3DInheritanceType.SINGLE_TABLE) > @DiscriminatorColumn(name=3D"Typ", > discriminatorType=3DDiscriminatorType.STRING) > @ManagedInterface > public interface Parameter extends Serializable{ > @Id > @GeneratedValue(strategy=3DGenerationType.IDENTITY) > public long getId(); > public void setId(long newId); > =20 > @Column(name=3D"KOMPONENTENTYP", length=3D50) > public String getKomponentenTyp(); > public void setKomponentenTyp(String newKomponentenTyp); > } >=20 > =20 > @Entity(name=3D"ATOMAR") > @ManagedInterface > public interface ParameterAtomar extends Parameter { >=20 > @Column(name=3D"NAME", length=3D50) > public String getName(); > public void setName(String newName); > =20 > @Column(name=3D"BEZEICHNUNG", length=3D50) > public String getBezeichnung(); > public void setBezeichnung(String bezeichnung); > } > =20 > @Entity > @ManagedInterface > public interface ParameterListeAtomar extends ParameterAtomar { > public String getInhalt(); > public void setInhalt(String newInhalt); > =20 > public void addToListenWerte(String o); > public void removeFromListenWerte(String o); > =20 > public DomainAssociation fetchDomainAssociation(); > } > =20 > public class KategorieImpl implements Kategorie, Serializable { > .............. > } > =20 > public class TypImpl implements Typ, Serializable { > ............. > } > =20 > public abstract class ParameterImpl implements Parameter, Serializable { > ............ > } > =20 > public abstract class ParameterAtomarImpl extends ParameterImpl implement= s > ParameterAtomar { > ........... > } > =20 > =20 > public class ParameterListeAtomarImpl extends ParameterAtomarImpl > implements > ParameterListeAtomar{ > private String inhalt; > private List listenWerte; > =20 > public ParameterListeAtomarImpl() { > } > =20 > private String getInhalt() { > return this.inhalt; > }=20 > =20 > private void setInhalt(String newInhalt) { > this.inhalt =3D newInhalt; > // do something else > } >=20 > private java.util.List getListenWerte() { > return this.listenWerte; > } > =20 > private void setListenWerte(java.util.List newListenWerte) { > this.listenWerte =3D newListenWerte; > // do something else > } > =20 > public void addToListenWerte(String o) { > this.getListenWerte().add(o); > // do something else > } > =20 > public void removeFromListenWerte(String o) { > this.getListenWerte().remove(o); > // do something else } > =20 > =20 > public DomainAssociation fetchDomainAssociation(){ > DomainAssociation da =3D //fetch a special object for further use > return da; > } > } >=20 > =20 > =20 > =20 >=20 >=20 --=20 View this message in context: http://n2.nabble.com/ManagedInterfaces-tp2438= 473p2445629.html Sent from the OpenJPA Users mailing list archive at Nabble.com.