openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Patrick Linskey" <plins...@gmail.com>
Subject Re: Containment with auto-generated id in openjpa
Date Mon, 29 Oct 2007 17:20:40 GMT
> is giving me headache. The openjpa requires a default constructor, and
> class Y cannot have a default constructor,
> because part of its composite primary key is a generated id of the
> parent class X.

The requirement for a default constructor is for internal purposes
only. You should be able to make the constructor protected or private
if you'd like. Alternately, if you're running the OpenJPA
post-compilation enhancer, then the default constructor should be
automatically added as needed.

-Patrick

On 10/25/07, Gul Onural <onural@nortel.com> wrote:
>
> Hi,
>
> I have a class X with an autogenerated primary key. Also there is a
> class Y which has a composite
> primary key of X's id and two other string.
>
> X has one to many relationship to Y and Y has many-to-one relationship
> to X.
>
> I am trying to use openjpa to model these two classes. But using the
> autogenerated id as a foreign key
> is giving me headache. The openjpa requires a default constructor, and
> class Y cannot have a default constructor,
> because part of its composite primary key is a generated id of the
> parent class X.
>
> Would openjpa properly work if I remove Y's foreign key from its
> composite pk ? What is the best way to
> model these objects in openjpa?
>
> public class X {
>    private long id; // autogenerated pk
>    private Y attrs;
> }
>
> public class Y {
>     private long id; // foreign key to X.id and part of Y's composite pk
>     private String a; // pk
>     private String b; // pk
> }
>
>


-- 
Patrick Linskey
202 669 5907

Mime
View raw message