You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Stefano Juri (JIRA)" <ji...@apache.org> on 2007/03/13 15:22:09 UTC

[jira] Created: (OPENJPA-171) EntityManager.getReference() returns an object of a wronc class

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 : 
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
	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">
	<!-- 
	<mapped-superclass
		class="ch.admin.bit.fw2.bm.AbstractBusinessObjectImpl">
		<attributes>
			<id name="id">
				<column name="ID" />
				<generated-value strategy="SEQUENCE" generator="TimeSeq"/>
				<sequence-generator name="TimeSeq" sequence-name="time()"/>
			</id>
			<version name="version" />
		</attributes>
	</mapped-superclass>
	 -->
	
	<entity class="ch.admin.bit.fw2.demo.bm.address.AbstractAddressImpl">
		<table name="ADDRESS"></table>
		<inheritance strategy="SINGLE_TABLE"/>
		<discriminator-column name="DISCRIMINANT" length="1"/>
		<attributes>
			<basic name="addressName">
				<column name="ADDRESS_NAME"/>
			</basic>
		</attributes>
	</entity>
	
	<entity class="ch.admin.bit.fw2.demo.bm.address.EMailAddressImpl">
		<discriminator-value>E</discriminator-value>
		<attributes>
			<basic name="domain">
				<column name="EMAIL_DOMAIN"/>
			</basic>
			<basic name="name">
				<column name="EMAIL_NAME"/>
			</basic>
		</attributes>
	</entity>
	
	<entity class="ch.admin.bit.fw2.demo.bm.address.PostalAddressImpl">
		<discriminator-value>P</discriminator-value>
		<attributes>
			<basic name="firstName">
				<column name="FIRST_NAME"/>
			</basic>
			<basic name="lastName">
				<column name="LAST_NAME"/>
			</basic>
			<basic name="street"></basic>
			<basic name="country"></basic>
			<basic name="zip"></basic>
			<basic name="city"></basic>
		</attributes>
	</entity>
	
	<entity class="ch.admin.bit.fw2.demo.bm.person.PersonImpl">
		<table name="PERSON" />
		<attributes>
			<basic name="title" />
			<basic name="firstName">
				<column name="FIRST_NAME" />
			</basic>
			<basic name="lastName">
				<column name="LAST_NAME" />
			</basic>
			<one-to-many name="addresses"
				target-entity="ch.admin.bit.fw2.demo.bm.address.AbstractAddressImpl">
				<join-table name="PERS_ADDR">
					<join-column name="ID_PERSON" />
					<inverse-join-column name="ID_ADDRESS" />
				</join-table>
			</one-to-many>
		</attributes>
	</entity>
	
</entity-mappings>

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.


[jira] Commented: (OPENJPA-171) EntityManager.getReference() returns an object of a wronc class

Posted by "Abe White (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-171?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12480510 ] 

Abe White commented on OPENJPA-171:
-----------------------------------

I attempted to reproduce this in a very simple test case but failed.  We'll need a user-supplied test case.  As a technical aside, I'm having trouble seeing how the "T getReference(Class<T> cls, Object id)" method could possibly return anything other than a "T" instance.

> 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 : 
> <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
> 	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">
> 	<mapped-superclass
> 		class="ch.admin.bit.fw2.bm.AbstractBusinessObjectImpl">
> 		<attributes>
> 			<id name="id">
> 				<column name="ID" />
> 				<generated-value strategy="SEQUENCE" generator="TimeSeq"/>
> 				<sequence-generator name="TimeSeq" sequence-name="time()"/>
> 			</id>
> 			<version name="version" />
> 		</attributes>
> 	</mapped-superclass>
> 	
> 	<entity class="ch.admin.bit.fw2.demo.bm.address.AbstractAddressImpl">
> 		<table name="ADDRESS"></table>
> 		<inheritance strategy="SINGLE_TABLE"/>
> 		<discriminator-column name="DISCRIMINANT" length="1"/>
> 		<attributes>
> 			<basic name="addressName">
> 				<column name="ADDRESS_NAME"/>
> 			</basic>
> 		</attributes>
> 	</entity>
> 	
> 	<entity class="ch.admin.bit.fw2.demo.bm.address.EMailAddressImpl">
> 		<discriminator-value>E</discriminator-value>
> 		<attributes>
> 			<basic name="domain">
> 				<column name="EMAIL_DOMAIN"/>
> 			</basic>
> 			<basic name="name">
> 				<column name="EMAIL_NAME"/>
> 			</basic>
> 		</attributes>
> 	</entity>
> 	
> 	<entity class="ch.admin.bit.fw2.demo.bm.address.PostalAddressImpl">
> 		<discriminator-value>P</discriminator-value>
> 		<attributes>
> 			<basic name="firstName">
> 				<column name="FIRST_NAME"/>
> 			</basic>
> 			<basic name="lastName">
> 				<column name="LAST_NAME"/>
> 			</basic>
> 			<basic name="street"></basic>
> 			<basic name="country"></basic>
> 			<basic name="zip"></basic>
> 			<basic name="city"></basic>
> 		</attributes>
> 	</entity>
> 	
> 	<entity class="ch.admin.bit.fw2.demo.bm.person.PersonImpl">
> 		<table name="PERSON" />
> 		<attributes>
> 			<basic name="title" />
> 			<basic name="firstName">
> 				<column name="FIRST_NAME" />
> 			</basic>
> 			<basic name="lastName">
> 				<column name="LAST_NAME" />
> 			</basic>
> 			<one-to-many name="addresses"
> 				target-entity="ch.admin.bit.fw2.demo.bm.address.AbstractAddressImpl">
> 				<join-table name="PERS_ADDR">
> 					<join-column name="ID_PERSON" />
> 					<inverse-join-column name="ID_ADDRESS" />
> 				</join-table>
> 			</one-to-many>
> 		</attributes>
> 	</entity>
> 	
> </entity-mappings>
> 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.


[jira] Commented: (OPENJPA-171) EntityManager.getReference() returns an object of a wronc class

Posted by "Abe White (JIRA)" <ji...@apache.org>.
    [ 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 : 
> <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
> 	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">
> 	<mapped-superclass
> 		class="ch.admin.bit.fw2.bm.AbstractBusinessObjectImpl">
> 		<attributes>
> 			<id name="id">
> 				<column name="ID" />
> 				<generated-value strategy="SEQUENCE" generator="TimeSeq"/>
> 				<sequence-generator name="TimeSeq" sequence-name="time()"/>
> 			</id>
> 			<version name="version" />
> 		</attributes>
> 	</mapped-superclass>
> 	
> 	<entity class="ch.admin.bit.fw2.demo.bm.address.AbstractAddressImpl">
> 		<table name="ADDRESS"></table>
> 		<inheritance strategy="SINGLE_TABLE"/>
> 		<discriminator-column name="DISCRIMINANT" length="1"/>
> 		<attributes>
> 			<basic name="addressName">
> 				<column name="ADDRESS_NAME"/>
> 			</basic>
> 		</attributes>
> 	</entity>
> 	
> 	<entity class="ch.admin.bit.fw2.demo.bm.address.EMailAddressImpl">
> 		<discriminator-value>E</discriminator-value>
> 		<attributes>
> 			<basic name="domain">
> 				<column name="EMAIL_DOMAIN"/>
> 			</basic>
> 			<basic name="name">
> 				<column name="EMAIL_NAME"/>
> 			</basic>
> 		</attributes>
> 	</entity>
> 	
> 	<entity class="ch.admin.bit.fw2.demo.bm.address.PostalAddressImpl">
> 		<discriminator-value>P</discriminator-value>
> 		<attributes>
> 			<basic name="firstName">
> 				<column name="FIRST_NAME"/>
> 			</basic>
> 			<basic name="lastName">
> 				<column name="LAST_NAME"/>
> 			</basic>
> 			<basic name="street"></basic>
> 			<basic name="country"></basic>
> 			<basic name="zip"></basic>
> 			<basic name="city"></basic>
> 		</attributes>
> 	</entity>
> 	
> 	<entity class="ch.admin.bit.fw2.demo.bm.person.PersonImpl">
> 		<table name="PERSON" />
> 		<attributes>
> 			<basic name="title" />
> 			<basic name="firstName">
> 				<column name="FIRST_NAME" />
> 			</basic>
> 			<basic name="lastName">
> 				<column name="LAST_NAME" />
> 			</basic>
> 			<one-to-many name="addresses"
> 				target-entity="ch.admin.bit.fw2.demo.bm.address.AbstractAddressImpl">
> 				<join-table name="PERS_ADDR">
> 					<join-column name="ID_PERSON" />
> 					<inverse-join-column name="ID_ADDRESS" />
> 				</join-table>
> 			</one-to-many>
> 		</attributes>
> 	</entity>
> 	
> </entity-mappings>
> 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.


[jira] Updated: (OPENJPA-171) EntityManager.getReference() returns an object of a wronc class

Posted by "Stefano Juri (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-171?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Stefano Juri updated OPENJPA-171:
---------------------------------

    Description: 
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 : 
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
	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">

	<mapped-superclass
		class="ch.admin.bit.fw2.bm.AbstractBusinessObjectImpl">
		<attributes>
			<id name="id">
				<column name="ID" />
				<generated-value strategy="SEQUENCE" generator="TimeSeq"/>
				<sequence-generator name="TimeSeq" sequence-name="time()"/>
			</id>
			<version name="version" />
		</attributes>
	</mapped-superclass>
	
	<entity class="ch.admin.bit.fw2.demo.bm.address.AbstractAddressImpl">
		<table name="ADDRESS"></table>
		<inheritance strategy="SINGLE_TABLE"/>
		<discriminator-column name="DISCRIMINANT" length="1"/>
		<attributes>
			<basic name="addressName">
				<column name="ADDRESS_NAME"/>
			</basic>
		</attributes>
	</entity>
	
	<entity class="ch.admin.bit.fw2.demo.bm.address.EMailAddressImpl">
		<discriminator-value>E</discriminator-value>
		<attributes>
			<basic name="domain">
				<column name="EMAIL_DOMAIN"/>
			</basic>
			<basic name="name">
				<column name="EMAIL_NAME"/>
			</basic>
		</attributes>
	</entity>
	
	<entity class="ch.admin.bit.fw2.demo.bm.address.PostalAddressImpl">
		<discriminator-value>P</discriminator-value>
		<attributes>
			<basic name="firstName">
				<column name="FIRST_NAME"/>
			</basic>
			<basic name="lastName">
				<column name="LAST_NAME"/>
			</basic>
			<basic name="street"></basic>
			<basic name="country"></basic>
			<basic name="zip"></basic>
			<basic name="city"></basic>
		</attributes>
	</entity>
	
	<entity class="ch.admin.bit.fw2.demo.bm.person.PersonImpl">
		<table name="PERSON" />
		<attributes>
			<basic name="title" />
			<basic name="firstName">
				<column name="FIRST_NAME" />
			</basic>
			<basic name="lastName">
				<column name="LAST_NAME" />
			</basic>
			<one-to-many name="addresses"
				target-entity="ch.admin.bit.fw2.demo.bm.address.AbstractAddressImpl">
				<join-table name="PERS_ADDR">
					<join-column name="ID_PERSON" />
					<inverse-join-column name="ID_ADDRESS" />
				</join-table>
			</one-to-many>
		</attributes>
	</entity>
	
</entity-mappings>

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');


  was:
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 : 
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
	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">
	<!-- 
	<mapped-superclass
		class="ch.admin.bit.fw2.bm.AbstractBusinessObjectImpl">
		<attributes>
			<id name="id">
				<column name="ID" />
				<generated-value strategy="SEQUENCE" generator="TimeSeq"/>
				<sequence-generator name="TimeSeq" sequence-name="time()"/>
			</id>
			<version name="version" />
		</attributes>
	</mapped-superclass>
	 -->
	
	<entity class="ch.admin.bit.fw2.demo.bm.address.AbstractAddressImpl">
		<table name="ADDRESS"></table>
		<inheritance strategy="SINGLE_TABLE"/>
		<discriminator-column name="DISCRIMINANT" length="1"/>
		<attributes>
			<basic name="addressName">
				<column name="ADDRESS_NAME"/>
			</basic>
		</attributes>
	</entity>
	
	<entity class="ch.admin.bit.fw2.demo.bm.address.EMailAddressImpl">
		<discriminator-value>E</discriminator-value>
		<attributes>
			<basic name="domain">
				<column name="EMAIL_DOMAIN"/>
			</basic>
			<basic name="name">
				<column name="EMAIL_NAME"/>
			</basic>
		</attributes>
	</entity>
	
	<entity class="ch.admin.bit.fw2.demo.bm.address.PostalAddressImpl">
		<discriminator-value>P</discriminator-value>
		<attributes>
			<basic name="firstName">
				<column name="FIRST_NAME"/>
			</basic>
			<basic name="lastName">
				<column name="LAST_NAME"/>
			</basic>
			<basic name="street"></basic>
			<basic name="country"></basic>
			<basic name="zip"></basic>
			<basic name="city"></basic>
		</attributes>
	</entity>
	
	<entity class="ch.admin.bit.fw2.demo.bm.person.PersonImpl">
		<table name="PERSON" />
		<attributes>
			<basic name="title" />
			<basic name="firstName">
				<column name="FIRST_NAME" />
			</basic>
			<basic name="lastName">
				<column name="LAST_NAME" />
			</basic>
			<one-to-many name="addresses"
				target-entity="ch.admin.bit.fw2.demo.bm.address.AbstractAddressImpl">
				<join-table name="PERS_ADDR">
					<join-column name="ID_PERSON" />
					<inverse-join-column name="ID_ADDRESS" />
				</join-table>
			</one-to-many>
		</attributes>
	</entity>
	
</entity-mappings>

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');



> 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 : 
> <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
> 	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">
> 	<mapped-superclass
> 		class="ch.admin.bit.fw2.bm.AbstractBusinessObjectImpl">
> 		<attributes>
> 			<id name="id">
> 				<column name="ID" />
> 				<generated-value strategy="SEQUENCE" generator="TimeSeq"/>
> 				<sequence-generator name="TimeSeq" sequence-name="time()"/>
> 			</id>
> 			<version name="version" />
> 		</attributes>
> 	</mapped-superclass>
> 	
> 	<entity class="ch.admin.bit.fw2.demo.bm.address.AbstractAddressImpl">
> 		<table name="ADDRESS"></table>
> 		<inheritance strategy="SINGLE_TABLE"/>
> 		<discriminator-column name="DISCRIMINANT" length="1"/>
> 		<attributes>
> 			<basic name="addressName">
> 				<column name="ADDRESS_NAME"/>
> 			</basic>
> 		</attributes>
> 	</entity>
> 	
> 	<entity class="ch.admin.bit.fw2.demo.bm.address.EMailAddressImpl">
> 		<discriminator-value>E</discriminator-value>
> 		<attributes>
> 			<basic name="domain">
> 				<column name="EMAIL_DOMAIN"/>
> 			</basic>
> 			<basic name="name">
> 				<column name="EMAIL_NAME"/>
> 			</basic>
> 		</attributes>
> 	</entity>
> 	
> 	<entity class="ch.admin.bit.fw2.demo.bm.address.PostalAddressImpl">
> 		<discriminator-value>P</discriminator-value>
> 		<attributes>
> 			<basic name="firstName">
> 				<column name="FIRST_NAME"/>
> 			</basic>
> 			<basic name="lastName">
> 				<column name="LAST_NAME"/>
> 			</basic>
> 			<basic name="street"></basic>
> 			<basic name="country"></basic>
> 			<basic name="zip"></basic>
> 			<basic name="city"></basic>
> 		</attributes>
> 	</entity>
> 	
> 	<entity class="ch.admin.bit.fw2.demo.bm.person.PersonImpl">
> 		<table name="PERSON" />
> 		<attributes>
> 			<basic name="title" />
> 			<basic name="firstName">
> 				<column name="FIRST_NAME" />
> 			</basic>
> 			<basic name="lastName">
> 				<column name="LAST_NAME" />
> 			</basic>
> 			<one-to-many name="addresses"
> 				target-entity="ch.admin.bit.fw2.demo.bm.address.AbstractAddressImpl">
> 				<join-table name="PERS_ADDR">
> 					<join-column name="ID_PERSON" />
> 					<inverse-join-column name="ID_ADDRESS" />
> 				</join-table>
> 			</one-to-many>
> 		</attributes>
> 	</entity>
> 	
> </entity-mappings>
> 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.