You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Marc Logemann <li...@logemann.org> on 2010/09/16 15:43:09 UTC
OpenJPA 1.2.x - weird inverse 1:n problem
Hi,
i am getting crazy. Hope someone can point me to the right spot. Suppose the following tables:
DB-Table: orders
--------
oid int
...
DB-Table: Adress
----------
oid int
order_oid
Now my classes:
@Entity
@Table(name = "orders")
public class Order {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "oid")
int oid;
@OneToMany(mappedBy = "order", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
List<DeliveryAddress> deliveryAddresses;
....
})
@Entity
public class DeliveryAddress extends Address {
.... (Id and Table annotation from superclass. Id field is also "oid")
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name="order_oid", referencedColumnName="oid")
Order order;
}
Now when i persist my order table, everything is fine but the foreign key "order_oid" inside the address table is null. Same goes on for other mappings as well. Whats the problem here?
Thanks.
---
regards
Marc Logemann
http://www.logemann.org
http://www.logentis.de
Re: OpenJPA 1.2.x - weird inverse 1:n problem
Posted by Michael Dick <mi...@gmail.com>.
In general OpenJPA does not manage the inverse relationship for you. However
you can use the openjpa.InverseManager property to tell us to do so.
Take a look at this
section<http://openjpa.apache.org/builds/1.2.2/apache-openjpa-1.2.2/docs/manual/manual.html#ref_guide_inverses>of
the manual for a more detailed explanation.
If you're already using openjpa.InverseManager then it looks like you've hit
a bug, and we'll have to take a closer look.
HTH
-mike
On Thu, Sep 16, 2010 at 9:06 AM, Marc Logemann <li...@logemann.org> wrote:
> Hi,
>
> trying to narrow it down myself and asking if i am right: Can it be that i
> need to manually manage the inverse relationship before persist?
>
> This would mean that i need to do something like that before persisting:
>
> for(DeliveryAddress dAddress : order.getDeliveryAddresses()) {
> dAddress.setOrder(order);
> }
>
> Looks weird because i thought the provider can do this magic for me :-)
>
> ---
> regards
> Marc Logemann
> http://www.logemann.org
> http://www.logentis.de
>
>
>
>
> Am 16.09.2010 um 15:43 schrieb Marc Logemann:
>
> > Hi,
> >
> > i am getting crazy. Hope someone can point me to the right spot. Suppose
> the following tables:
> >
> > DB-Table: orders
> > --------
> > oid int
> > ...
> >
> >
> > DB-Table: Adress
> > ----------
> > oid int
> > order_oid
> >
> >
> >
> > Now my classes:
> >
> > @Entity
> > @Table(name = "orders")
> > public class Order {
> > @Id
> > @GeneratedValue(strategy = GenerationType.IDENTITY)
> > @Column(name = "oid")
> > int oid;
> >
> > @OneToMany(mappedBy = "order", fetch = FetchType.EAGER, cascade =
> CascadeType.ALL)
> > List<DeliveryAddress> deliveryAddresses;
> > ....
> > })
> >
> > @Entity
> > public class DeliveryAddress extends Address {
> > .... (Id and Table annotation from superclass. Id field is also
> "oid")
> >
> > @ManyToOne(cascade = CascadeType.ALL)
> > @JoinColumn(name="order_oid", referencedColumnName="oid")
> > Order order;
> > }
> >
> >
> > Now when i persist my order table, everything is fine but the foreign key
> "order_oid" inside the address table is null. Same goes on for other
> mappings as well. Whats the problem here?
> >
> > Thanks.
> >
> > ---
> > regards
> > Marc Logemann
> > http://www.logemann.org
> > http://www.logentis.de
> >
> >
> >
> >
>
>
Re: OpenJPA 1.2.x - weird inverse 1:n problem
Posted by Marc Logemann <li...@logemann.org>.
Hi,
trying to narrow it down myself and asking if i am right: Can it be that i need to manually manage the inverse relationship before persist?
This would mean that i need to do something like that before persisting:
for(DeliveryAddress dAddress : order.getDeliveryAddresses()) {
dAddress.setOrder(order);
}
Looks weird because i thought the provider can do this magic for me :-)
---
regards
Marc Logemann
http://www.logemann.org
http://www.logentis.de
Am 16.09.2010 um 15:43 schrieb Marc Logemann:
> Hi,
>
> i am getting crazy. Hope someone can point me to the right spot. Suppose the following tables:
>
> DB-Table: orders
> --------
> oid int
> ...
>
>
> DB-Table: Adress
> ----------
> oid int
> order_oid
>
>
>
> Now my classes:
>
> @Entity
> @Table(name = "orders")
> public class Order {
> @Id
> @GeneratedValue(strategy = GenerationType.IDENTITY)
> @Column(name = "oid")
> int oid;
>
> @OneToMany(mappedBy = "order", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
> List<DeliveryAddress> deliveryAddresses;
> ....
> })
>
> @Entity
> public class DeliveryAddress extends Address {
> .... (Id and Table annotation from superclass. Id field is also "oid")
>
> @ManyToOne(cascade = CascadeType.ALL)
> @JoinColumn(name="order_oid", referencedColumnName="oid")
> Order order;
> }
>
>
> Now when i persist my order table, everything is fine but the foreign key "order_oid" inside the address table is null. Same goes on for other mappings as well. Whats the problem here?
>
> Thanks.
>
> ---
> regards
> Marc Logemann
> http://www.logemann.org
> http://www.logentis.de
>
>
>
>