You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by stlecho <st...@gmail.com> on 2010/06/18 16:41:27 UTC

Mapping different Embedded of the same type to the same table

Hi,

I would like to map 2 Embedded properties with the same Embeddable to the
same table. When using underneath shown config, OpenJPA generates an
InvalidStateException (see stacktrace below).

Ideally, the Response.normalDetail and Response.servicesDetail properties
should be mapped respectively to
T_RESPONSE.NORMAL_AMOUNT,T_RESPONSE.NORMAL_DESCR and
T_RESPONSE.SERV_AMOUNT,T_RESPONSE.SERV_DESCR.

Is it possible to specify the NORMAL_ and SERVICES_ column prefixes in the
configuration of the Embedded properties ? If the answer is "no", which
alternatives do I have to solve this issue ?

@Entity
@Table(name="T_RESPONSE")
public class Response
   @Embedded
   protected Detail normalDetail;
   @Embedded
   protected Detail servicesDetail;

@Embeddable
public class Detail   
   protected Integer amount;
   protected String description;

Stacktrace
Caused by: <openjpa-1.2.2-r422266:898935 fatal user error>
org.apache.openjpa.persistence.InvalidStateException: Attempt to set column
"Response.amount" to two different values: (class java.lang.Integer)"10",
(class java.lang.Integer)"1" This can occur when you fail to set both sides
of a two-sided relation between objects, or when you map different fields to
the same column, but you do not keep the values of these fields in synch. 
    at org.apache.openjpa.jdbc.sql.PrimaryRow.setObject(PrimaryRow.java:339) 
    at org.apache.openjpa.jdbc.sql.RowImpl.setObject(RowImpl.java:504) 
    at
org.apache.openjpa.jdbc.meta.strats.EmbedFieldStrategy$EmbeddedRow.setObject(EmbedFieldStrategy.java:1416) 

-- 
View this message in context: http://openjpa.208410.n2.nabble.com/Mapping-different-Embedded-of-the-same-type-to-the-same-table-tp5195526p5195526.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Mapping different Embedded of the same type to the same table

Posted by stlecho <st...@gmail.com>.
That solved the problem. Thanks a lot you for your help.


Fay Wang wrote:
> 
> http://openjpa.apache.org/builds/1.0.2/apache-openjpa-1.0.2/docs/manual/jpa_overview_mapping_field.html#jpa_overview_mapping_embed
> 

-- 
View this message in context: http://openjpa.208410.n2.nabble.com/Mapping-different-Embedded-of-the-same-type-to-the-same-table-tp5195526p5205981.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Mapping different Embedded of the same type to the same table

Posted by Fay Wang <fy...@yahoo.com>.
Hi, 
       You can use @AttributeOverride to override the mapping of an embeddable field. 

http://openjpa.apache.org/builds/1.0.2/apache-openjpa-1.0.2/docs/manual/jpa_overview_mapping_field.html#jpa_overview_mapping_embed

Fay



----- Original Message ----
From: stlecho <st...@gmail.com>
To: users@openjpa.apache.org
Sent: Fri, June 18, 2010 7:41:27 AM
Subject: Mapping different Embedded of the same type to the same table


Hi,

I would like to map 2 Embedded properties with the same Embeddable to the
same table. When using underneath shown config, OpenJPA generates an
InvalidStateException (see stacktrace below).

Ideally, the Response.normalDetail and Response.servicesDetail properties
should be mapped respectively to
T_RESPONSE.NORMAL_AMOUNT,T_RESPONSE.NORMAL_DESCR and
T_RESPONSE.SERV_AMOUNT,T_RESPONSE.SERV_DESCR.

Is it possible to specify the NORMAL_ and SERVICES_ column prefixes in the
configuration of the Embedded properties ? If the answer is "no", which
alternatives do I have to solve this issue ?

@Entity
@Table(name="T_RESPONSE")
public class Response
   @Embedded
   protected Detail normalDetail;
   @Embedded
   protected Detail servicesDetail;

@Embeddable
public class Detail  
   protected Integer amount;
   protected String description;

Stacktrace
Caused by: <openjpa-1.2.2-r422266:898935 fatal user error>
org.apache.openjpa.persistence.InvalidStateException: Attempt to set column
"Response.amount" to two different values: (class java.lang.Integer)"10",
(class java.lang.Integer)"1" This can occur when you fail to set both sides
of a two-sided relation between objects, or when you map different fields to
the same column, but you do not keep the values of these fields in synch. 
    at org.apache.openjpa.jdbc.sql.PrimaryRow.setObject(PrimaryRow.java:339) 
    at org.apache.openjpa.jdbc.sql.RowImpl.setObject(RowImpl.java:504) 
    at
org.apache.openjpa.jdbc.meta.strats.EmbedFieldStrategy$EmbeddedRow.setObject(EmbedFieldStrategy.java:1416) 

-- 
View this message in context: http://openjpa.208410.n2.nabble.com/Mapping-different-Embedded-of-the-same-type-to-the-same-table-tp5195526p5195526.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.