openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fay Wang <fyw...@yahoo.com>
Subject Re: Mapping different Embedded of the same type to the same table
Date Fri, 18 Jun 2010 17:01:39 GMT
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 <stlecho@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.



      


Mime
View raw message