I call org.apache.openjpa.enhance.PCEnhancer Annette
Annette Scherer Abteilung Informatik HUK-COBURG Bahnhofsplatz 96444 Coburg Telefon 09561 96-1718 Telefax 09561 96-3671 E-Mail [email protected] Internet www.HUK.de ============================================================= HUK-COBURG Haftpflicht-Unterstützungs-Kasse kraftfahrender Beamter Deutschlands a. G. in Coburg Reg.-Gericht Coburg HRB 100; St.-Nr. 9212/101/00021 Sitz der Gesellschaft: Bahnhofsplatz, 96444 Coburg Vorsitzender des Aufsichtsrats: Werner Strohmayr. Vorstand: Rolf-Peter Hoenen (Sprecher), Wolfgang Flaßhoff, Stefan Gronbach, Klaus-Jürgen Heitmann, Dr. Christian Hofer, Dr. Wolfgang Weiler. ============================================================= -----Ursprüngliche Nachricht----- Von: Rick Curtis [mailto:[email protected]] Gesendet: Montag, 9. März 2009 14:24 An: [email protected] Betreff: Re: AW: ManagedInterfaces Annette - How are you enhancing your Entities? -Rick Scherer, Annette wrote: > > Hi, > > unfortunately this approach does not lead to desired behaviour. When > instantiating our implemented class with ParameterListeAtomar pc = new > ParameterListeAtomarImpl(...) as suggested, we receive another error: > > Exception in thread "main" <openjpa-1.2.0-r422266:683325 nonfatal user > error> org.apache.openjpa.persistence.ArgumentException: Attempt to cast > instance "de.huk.vtp.selektionen.bo.parameterlisteatomari...@10e35d5" to > PersistenceCapable failed. Ensure that it has been enhanced. > > > This corresponds to Apache OpenJPA User's Gide > (http://openjpa.apache.org/builds/1.2.0/apache-openjpa-1.2.0/docs/manual/manual.html#ref_guide_pc_interfaces) > > What else can we do? > > > Greetings > Annette Scherer > > > > > -----Ursprüngliche Nachricht----- > Von: Pinaki Poddar [mailto:[email protected]] > Gesendet: Sonntag, 8. März 2009 19:50 > An: [email protected] > Betreff: Re: ManagedInterfaces > > > Hi, > > 3. we use OpenJPAEntityManager.createInstance(Class) to instantiate > objects > > This method will create a class *dynamically* which implements the > given > interface. > 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 = new ParameterListeAtomarImpl(...); > > You can continue using the interface for find() or query such as > ParameterListeAtomar pc = em.find(ParameterListeAtomar.class, someId); > This should return you an instance of ParameterListeAtomarImpl which has > the correct implementation of fetchDomainAssociation(). > > > > > > Annette Scherer wrote: >> >> Hello, >> >> we have several problems using OpenJPA with managed interfaces. >> I try to explain: >> >> 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 >> >> >> 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. >> >> >> >> 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.fetchDo >> mainAssociation(Unknown Source) >> >> 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. >> >> >> >> 2. another problem is the use of inheritance. With annotations we used >> for >> Parameter, ParameterAtomar for example, we receive this exeption: >> [04.03.09 14:17:47:004 CET] 00000021 SystemOut O [04 Mär 2009 14:17:46] >> DEBUG [LifecycleImpl.java:259 -- phase] - afterPhase(RESTORE_VIEW >> 1,com.icesoft.faces.context.bridgefacescont...@60ae60ae) threw exception: >> <openjpa-1.2.0-r422266:683325 fatal user error> >> 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" >> >> <openjpa-1.2.0-r422266:683325 fatal user error> >> 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" >> >> at >> org.apache.openjpa.jdbc.meta.strats.ValueMapDiscriminatorStrategy.mapDiscrim >> inatorValue(ValueMapDiscriminatorStrategy.java:116) >> >> Thanks for you´r advice >> >> Annette Scherer >> >> >> >> >> >> >> >> >> extract of our model: >> >> @Entity >> @Table(name="TAKATEGORIE") >> @ManagedInterface >> public interface Kategorie extends Serializable{ >> @Id >> @Column(name="NAME", length=50) >> public String getName(); >> public void setName(String newName); >> >> @OneToMany(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST}) >> public java.util.List<Typ> getTypListe(); >> public void setTypListe(java.util.List<Typ> newTypListe); >> >> public void addToTypListe(Typ o); >> public void removeFromTypListe(Typ o); >> } >> >> >> @Entity >> @Table(name="TATYP") >> @ManagedInterface >> public interface Typ extends Serializable { >> @Id >> @Column(name="SELEKTIONSNUMMER", length=4) >> public String getSelectionID(); >> public void setSelectionID(String newOperationId); >> >> @Column(name="NAME", length=60) >> public String getName(); >> public void setName(String newName); >> >> @OneToMany(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST}) >> public java.util.List<Parameter> getParameterListe(); >> public void setParameterListe(java.util.List<Parameter> >> newParameterListe); >> >> public void addToParameterListe(Parameter o); >> public void removeFromParameterListe(Parameter o); >> } >> >> >> @Entity >> @Table(name="TAPARAMETER") >> @Inheritance(strategy=InheritanceType.SINGLE_TABLE) >> @DiscriminatorColumn(name="Typ", >> discriminatorType=DiscriminatorType.STRING) >> @ManagedInterface >> public interface Parameter extends Serializable{ >> @Id >> @GeneratedValue(strategy=GenerationType.IDENTITY) >> public long getId(); >> public void setId(long newId); >> >> @Column(name="KOMPONENTENTYP", length=50) >> public String getKomponentenTyp(); >> public void setKomponentenTyp(String newKomponentenTyp); >> } >> >> >> @Entity(name="ATOMAR") >> @ManagedInterface >> public interface ParameterAtomar extends Parameter { >> >> @Column(name="NAME", length=50) >> public String getName(); >> public void setName(String newName); >> >> @Column(name="BEZEICHNUNG", length=50) >> public String getBezeichnung(); >> public void setBezeichnung(String bezeichnung); >> } >> >> @Entity >> @ManagedInterface >> public interface ParameterListeAtomar extends ParameterAtomar { >> public String getInhalt(); >> public void setInhalt(String newInhalt); >> >> public void addToListenWerte(String o); >> public void removeFromListenWerte(String o); >> >> public DomainAssociation fetchDomainAssociation(); >> } >> >> public class KategorieImpl implements Kategorie, Serializable { >> .............. >> } >> >> public class TypImpl implements Typ, Serializable { >> ............. >> } >> >> public abstract class ParameterImpl implements Parameter, Serializable { >> ............ >> } >> >> public abstract class ParameterAtomarImpl extends ParameterImpl >> implements >> ParameterAtomar { >> ........... >> } >> >> >> public class ParameterListeAtomarImpl extends ParameterAtomarImpl >> implements >> ParameterListeAtomar{ >> private String inhalt; >> private List<String> listenWerte; >> >> public ParameterListeAtomarImpl() { >> } >> >> private String getInhalt() { >> return this.inhalt; >> } >> >> private void setInhalt(String newInhalt) { >> this.inhalt = newInhalt; >> // do something else >> } >> >> private java.util.List getListenWerte() { >> return this.listenWerte; >> } >> >> private void setListenWerte(java.util.List newListenWerte) { >> this.listenWerte = newListenWerte; >> // do something else >> } >> >> public void addToListenWerte(String o) { >> this.getListenWerte().add(o); >> // do something else >> } >> >> public void removeFromListenWerte(String o) { >> this.getListenWerte().remove(o); >> // do something else } >> >> >> public DomainAssociation fetchDomainAssociation(){ >> DomainAssociation da = //fetch a special object for further use >> return da; >> } >> } >> >> >> >> >> >> > > -- > View this message in context: > http://n2.nabble.com/ManagedInterfaces-tp2438473p2445629.html > Sent from the OpenJPA Users mailing list archive at Nabble.com. > > > -- View this message in context: http://n2.nabble.com/ManagedInterfaces-tp2438473p2448900.html Sent from the OpenJPA Users mailing list archive at Nabble.com.
