openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Madhu Kalaimalai <mba...@yahoo.com>
Subject Re: OpenJPA - two-sided relation between objects Issue
Date Tue, 12 Aug 2008 17:01:46 GMT

Hi Pinaki

Thanks for the reply.

I tried the bidirectional too with nullable true on the many-to-one side.

The problem being i have the existing code which uses addressId mapping <1>
below, I can't replace this with Address <2> mapping below becoz the old
code will not work which is using directly the identifier.

The objective now is to bring the relation with out affecting the existing
code which doesn't have the relations built

<1>
@Basic() 
@ Column(name=" ADDR_FK_ID",nullable=true) 
public Long getAddressId() 
{ 
return this.addressId; 
} 

<2>

Phone.java 
@ManyToOne 
@ Column(name=" ADDR_FK_ID",nullable=true) 
private Address address; 

When I try this option, I get the following error

ORA-00957: duplicate column name 

as I have both the mapping for the ADDR_FK_ID ie the column and the
many-to-one.

My question is there a way to selective turn off the column mapping when
going through the relation mapping . I thought of options like Embedded or
using an Interface etc,

As I said earlier, The existing code have simple pojos mapping one class to
one table w/o relationships built. We want to bring in object relation for
object graph persistence. Right now the developer writes code to persist the
data row by row rather than passing the object graph to persist.

Rgds
Madhu


Pinaki Poddar wrote:
> 
> Hi,
> 1. The mapping can be simplified as follows:
> Address.java:
> @OneToMany(mappedBy="address", cascade={CascadeType.ALL},
> fetch=FetchType.LAZY)
> private java.util.Set<Phone> phones;
> 
> Phone.java
> @ManyToOne
> @ Column(name=" ADDR_FK_ID",nullable=true)
> private Address address;
> 
> 2. It will get rid of the two independent mappings trying to update the
> same ADDR_FK_ID column.
> 
> 3. Domain model should ensure referential consistency at object level. For
> example,
> Address.java:
>    public void addPhone(Phone phone) {
>         phones.add(phone);
>         phone.setAddresss(this);
>     }
> 
> Phone.java:
>   // notice package level accss 
>   void setAddress(Address addr) {
>        this.address = addr;
>   }
> 
>   You can ask OpenJPA to manage consistency of inverse relations but at
> the cost of slight performance penalty.
> 
> 4. In O-R mapping, it makes more sense to work with object references than
> with identifiers -- that is why Phone should declare a field of Address
> type rather than a Long which is primary identifier of Address.
> 
> 

-- 
View this message in context: http://n2.nabble.com/OpenJPA---two-sided-relation-between-objects-Issue-tp687050p720046.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Mime
View raw message