openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Elias Torres <el...@torrez.us>
Subject Re: How to map multiple properties to same column as writable in jpa
Date Fri, 27 Jul 2007 13:39:06 GMT
Furthermore,

Because I haven't been able to do this dual-mapping of a column, I'm
forced to write JPQL queries like this:

SELECT f FROM Foo f JOIN f.user u WHERE u.id = ?

as opposed to when I have the user id already.

SELECT f FROM Foo f WHERE f.userid = ?

Is it a practice to create multiple versions of an entity (light vs
heavy) to optimize the queries? One with @ManyToOne and another with @Basic.

BTW, I'm neither an ORM/Relational Algebra expert just trying to
understand [Open]JPA. I have worked with Hibernate on Apache Roller and
also with iBatis.

-Elias

Elias Torres wrote:
> I was wondering the same thing (but with JPA of course). I tried and was
> getting a message that the members were out of sync.
> 
> @ManyToOne(fetch=FetchType.LAZY)
> @JoinColumn(name="userid", referencedColumnName="id")
> private User user;
> 
> and
> 
> @Column(name="userid")
> private String userId;
> 
> How would I go about keeping them in sync? Especially, when someone
> calls setUser(user) with a new instance that might not have an id.
> 
> Is there a way in OpenJPA to say that the userId column is only for
> read-only and not persist operations?
> 
> Thanks.
> 
> -Elias
> 
> Patrick Linskey wrote:
>> Hi,
>>
>> This forum is for the OpenJPA product, so we don't have much
>> experience with Toplink.
>>
>> However, from an OpenJPA standpoint, you can map the same column to
>> multiple fields without a problem, as long as you don't attempt to set
>> the fields to different values during the same transaction.
>>
>> -Patrick
>>
>> On 7/26/07, saravanan_tvm <skumar_rect2000@yahoo.com> wrote:
>>> Hi,
>>> I am using toplink from oracle to support JPA.
>>> I have the following requirement...
>>> i have to map same column for multiple properties using @joincolumn
>>> annotation.. eg its something like this
>>>
>>> @joincolumn(name="PARENT_RECORD_ID")
>>> private Drug drug
>>>
>>> @joincolumn(name="PARENT_RECORD_ID")
>>> private Reaction reaction
>>>
>>> PARENT_RECORD_ID is nothing but primary key of parent table.
>>> but while accessing the application i am getting the following exception....
>>>
>>>  MULTIPLE_WRITE_MAPPINGS_FOR_FIELD
>>>
>>> Cause: Multiple writable mappings for the field fieldName are defined in the
>>> descriptor. Exactly one must be defined as writable; the others must be
>>> specified as read-only. When multiple write mappings are defined for the
>>> field, TopLink is unable to choose the appropriate mapping for writing the
>>> value of the field in the database row. Therefore, the exception is raised
>>> during the validation process of descriptors.
>>>
>>> Action: Make one of those mappings read-only
>>>
>>> But i cannot make read only, if i make read only then while inserting new
>>> records it will be problem
>>>
>>> please can anyone provide the solution for this...
>>> Regards,
>>> Saravanan.
>>>
>>> --
>>> View this message in context: http://www.nabble.com/How-to-map-multiple-properties-to-same-column-as-writable-in-jpa-tf4155235.html#a11822480
>>> Sent from the OpenJPA Developers mailing list archive at Nabble.com.
>>>
>>>
>>
> 

Mime
View raw message