This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 173335 - derived/dependent identities not mapped correctly
Summary: derived/dependent identities not mapped correctly
Status: NEW
Alias: None
Product: javaee
Classification: Unclassified
Component: Persistence (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker (vote)
Assignee: Sergey Petrov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-09-30 05:36 UTC by err
Modified: 2009-10-01 20:00 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
ERD showing relationship at issue (38.35 KB, image/png)
2009-09-30 05:37 UTC, err
Details

Note You need to log in before you can comment on or make changes to this bug.
Description err 2009-09-30 05:36:24 UTC
In the spec:
    2.4.1 Primary Keys Corresponding to Derived Identities
        The identity of an entity may be derived from the identity of another entity (the "parent" entity) when
        the former entity (the "dependent" entity) is the owner of a many-to-one or one-to-one relationship to
        the parent entity and a foreign key maps the relationship from dependent to parent.

For example, in the attached ERD, consider the aspectDisplay table. "Enitty Classes from Database" generates something like:

    @Entity
    @Table(name = "ASPECTDISPLAY", catalog = "", schema = "ERNIE")
    public class Aspectdisplay implements Serializable {
        private static final long serialVersionUID = 1L;
        @EmbeddedId
        protected AspectdisplayPK aspectdisplayPK;
        @Basic(optional = false)
        @Lob
        @Column(name = "DAT", nullable = false)
        private Serializable dat;
        @JoinColumns({@JoinColumn(name = "CHART_ID", referencedColumnName =
                "CHART_ID", nullable = false, insertable = false, updatable = false), @JoinColumn(name =
                "EVENT_ID", referencedColumnName = "EVENT_ID", nullable = false, insertable =
                false, updatable = false)})
        @OneToOne(optional = false)
        private ChartEvent chartEvent;

wheras instead of using @JoinColumns, it should be done with @MappedById.

    @Entity
    @Table(name = "ASPECTDISPLAY", catalog = "", schema = "ERNIE")
    public class Aspectdisplay implements Serializable {
        private static final long serialVersionUID = 1L;
        @EmbeddedId
        protected ChartEventPK chartEventPK;
        @Basic(optional = false)
        @Lob
        @Column(name = "DAT", nullable = false)
        private Serializable dat;
        @MappedById // <<<<<<<<<<<<<<<<<<<<<<< instead of @JoinColumns
        @OneToOne(optional = false)
        private ChartEvent chartEvent;

Mapping this way allows the persistence provider to automatically set the primary key (chartEvent must be set).

(Note in the JPA 1.0 release this should be mapped with @PrimaryKeyJoinColumns, @MappedById is now the preferred mechanism)

This is loosely related to Issue 172075, but there is no dependency.
Comment 1 err 2009-09-30 05:37:11 UTC
Created attachment 88561 [details]
ERD showing relationship at issue
Comment 2 Sergey Petrov 2009-09-30 07:31:49 UTC
looks like enhancement of feature for better support new features from jpa 2.0, it's closely correlate with initial plan
for 6.8, but it seems it will not be implemented in 6.8.
Comment 3 err 2009-09-30 15:30:27 UTC
> > Note in the JPA 1.0 release this should be mapped with @PrimaryKeyJoinColumns, 
> > @MappedById is now the preferred mechanism

> enhancement of feature for better support new features from jpa 2.0

Looks like this was an issue with the JPA 1.0 support as well; since there is a mapping specifically for "primary key
column that is used as a foreign key to join to another table". 

However, I understand that there probably is not time to get it into 6.8; I'm just really glad I found it, it was
driving me nuts not being able to specify this in the mappings.
Comment 4 Sergey Petrov 2009-10-01 20:00:43 UTC
also if we are talking about derived identifiers, it seems this area isn't final yet in jpa 2.0 specification.