users@glassfish.java.net

Embedded objects

From: Ian Meikle <imeikle3_at_csc.com>
Date: Mon, 27 Feb 2006 13:03:39 +0100

Hi,

We are trying to convert an existing application to use EJB3 persistancy.
However we have come accross the following problems with the @Embedded
annotation:

1) How do you describe an embedded object which has a @ManyToOne relation
2) How do you describe an embedded object which has a @ManyToOne relation
to an other object that has multiple primary keys.

The problem we find is that the @AttributeOverride annotation seems to
only have support for overriding simple @Column
definitions. If you take a look at the example below.

@Embeddable
public class Foo {
        String name;
        @ManyToOne(fetch = FetchType.LAZY)
        @JoinColumn(name = "FK_BAR")
        Bar bar;
}

@Entity
public class Person {
        @Embedded
        @AttributeOverrides(
                @AttributeOverride(name="name",
column=_at_Column(name="FOO_NAME"))
                @AttributeOverride(name="bar", <what goes here ?>)
                )
        Foo foo;
}

This problem becomes ever worse if the entity referenced by the embedded
class has multiple primary keys.i.e.

@Entity
// The primary key of this class is a combination of CODE and VALUE
public class Bar {
        @Id
        String code;
        @Id
        String value;
}

In this case what would the Person definition be ?
Has this case been considered within EJB3 and how would it be modelled in
GlassFish ?

We think that it would be natural to have the possibility of defining a
@JoinColumn and/or a @JoinColumns definion
with the @AttributeOverride annotation. i.e.

public @interface AttributeOverride {
    String name();
    Column column() default = @Column();
    JoinColumn joinColumn() default = @JoinColumn();
    JoinColumns[] joinColumns() default = { };
}

where one and only one of column(), joinColumn() and joinColumns() is
allowed to be defined.

Would this be possible ? We do NOT have the possibility to change our DB
structure, so the persistancy framework
must be made to fit, not the reverse.

Many thanks
Ian Meikle
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
This is a PRIVATE message. If you are not the intended recipient, please
delete without copying and kindly advise us by e-mail of the mistake in
delivery. NOTE: Regardless of content, this e-mail shall not operate to
bind CSC to any order or other contract unless pursuant to explicit
written agreement or government initiative expressly permitting the use of
e-mail for such purpose.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------