[ https://issues.apache.org/jira/browse/OPENJPA-171?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12480455 ] Abe White commented on OPENJPA-171: ----------------------------------- It would speed things up a lot if you attached a working test case demonstrating the problem. > EntityManager.getReference() returns an object of a wronc class > --------------------------------------------------------------- > > Key: OPENJPA-171 > URL: https://issues.apache.org/jira/browse/OPENJPA-171 > Project: OpenJPA > Issue Type: Bug > Affects Versions: 0.9.6 > Reporter: Stefano Juri > > I have a simple class system : a PersonImpl owns a set of AbstractAddresses. An AbstractAddress can be an EMailAddressImpl or a PostalAddressImpl. All these objects extend AbstractBusinessObject. > When I call entityManager.getReference(PersonImpl.class, "1") I get the EMailAddressImpl object with id "1" instead of a PersonImpl object. > If I get the object with a query (select p from PersonImpl p where p.id='1') everything is ok. > My mapping file is : > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd" > version="1.0"> > class="ch.admin.bit.fw2.bm.AbstractBusinessObjectImpl"> > > > > > > > > > > > >
> > > > > > > >
> > > E > > > > > > > > > > > > P > > > > > > > > > > > > > > > > > > > > > > > > > target-entity="ch.admin.bit.fw2.demo.bm.address.AbstractAddressImpl"> > > > > > > > > > > And the database creation script is : > -------------------------------------------------- > -- Create Table ADDRESS > -------------------------------------------------- > Create table ADDRESS ( > ID VARCHAR(20) NOT NULL , > DISCRIMINANT CHARACTER(1) NOT NULL , > ADDRESS_NAME VARCHAR(35) NOT NULL , > EMAIL_DOMAIN VARCHAR(50) , > EMAIL_NAME VARCHAR(50) , > FIRST_NAME VARCHAR(35) , > LAST_NAME VARCHAR(35) , > STREET VARCHAR(35) , > CITY VARCHAR(35) , > ZIP VARCHAR(10) , > COUNTRY CHARACTER(2) , > VERSION TIMESTAMP > ) > ; > -------------------------------------------------- > -- Create Primary Key PRIMARY_KEY > -------------------------------------------------- > alter table ADDRESS > add constraint PERSON_KEY > Primary Key (ID); > -------------------------------------------------- > -- Create Table PERSON > -------------------------------------------------- > Create table PERSON ( > ID VARCHAR(20) NOT NULL , > FIRST_NAME VARCHAR(35) NOT NULL , > LAST_NAME VARCHAR(35) NOT NULL , > TITLE VARCHAR(35) NOT NULL , > VERSION TIMESTAMP > ) > ; > -------------------------------------------------- > -- Create Primary Key SQL060816161507820 > -------------------------------------------------- > alter table PERSON > add constraint ADDRESS_KEY > Primary Key (ID); > > -------------------------------------------------- > -- Create Table PERS_ADDR > -------------------------------------------------- > Create table PERS_ADDR ( > ID_PERSON VARCHAR(20) NOT NULL , > ID_ADDRESS VARCHAR(20) NOT NULL > ); > -------------------------------------------------- > -- Create Primary Key SQL060816161507820 > -------------------------------------------------- > alter table PERS_ADDR > add constraint PERS_ADDR_KEY > Primary Key (ID_PERSON,ID_ADDRESS); > > Insert into PERSON values('1', 'Enrico', 'Barilla', 'Mr',0); > Insert into PERSON values('2', 'Adelgrunde', 'Volkswagen', 'Ms',0); > > Insert into ADDRESS values('1', 'E', 'Home', 'barilla.it', 'enrico.barilla', NULL, NULL, NULL, NULL, NULL, NULL, 0); > Insert into ADDRESS values('2', 'P', 'Office', NULL, NULL, NULL, NULL, 'Käferstr. 78', 'Wolfsburg', '12345', 'DE', 0); > Insert into ADDRESS values('3', 'P', 'Home', NULL, NULL, NULL, NULL, 'Via delle Lasagne 12', 'Roma', '67890', 'IT', 0); > Insert into PERS_ADDR values ('1','1'); > Insert into PERS_ADDR values ('1','3'); > Insert into PERS_ADDR values ('2','2'); -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.