Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Complex Mapping question

As Tom suggests, you might want to try this with EclipseLink as at least the error it gives should help you narrow down what is going wrong. You also have reused database pk columns in your mappings, but marked each of those mappings with the @Id annotation. This is incorrect, as it implies that the multiple mappings control the same database column, which cannot happen. Only 1 can control a database column, the rest must be read-only otherwise it leads to potential conflicts. For instance, ObjectItemAssociationStatus has the subj_obj_item_id column mapped/controlled by both the objObjItem and objItemAssoc relationships. I can only assume your primary key class is also incorrect or overly complex to handle the extra mappings. Try making only objItemAssoc and ix the Id mappings to simplify things, and make the objObjItem and subjObjItem mappings read-only by marking the fields as updateable+insertable=false.

Best Regards,
Chris

On 17/02/2011 8:59 AM, Tom Ware wrote:
Are you having a problem in EclipseLink?  This forum is for EclipseLink.

If so, can you provide the details of how you have designed your mappings.

-Tom

Christopher Schmidt wrote:
Hi all,
I have a problem with the best mapping of two tables: obj_item_assoc and obj_item_assoc_stat. Both share 3 of its primary keys. The "XXX_obj_item" primary keys are a fk's to the entity ObjectItem - thats why I modeled it as @ManyToOne relations.


Is this generally OK how I did this (see below)?

Unfortunately this is not working with OpenJPA. So - thats why I am asking this here ;-)

Thanks Christopher



TABLE obj_item_assoc
(
  subj_obj_item_id numeric(20,0) NOT NULL,
  obj_obj_item_id numeric(20,0) NOT NULL,
  obj_item_assoc_ix numeric(20,0) NOT NULL,

CONSTRAINT obj_item_assoc_pkey PRIMARY KEY (subj_obj_item_id, obj_obj_item_id, obj_item_assoc_ix),

CONSTRAINT obj_item_assoc_obj_obj_item_id_fkey FOREIGN KEY (obj_obj_item_id)
      REFERENCES obj_item (obj_item_id),

CONSTRAINT obj_item_assoc_subj_obj_item_id_fkey FOREIGN KEY (subj_obj_item_id)
      REFERENCES obj_item (obj_item_id)
)


TABLE obj_item_assoc_stat
(
  subj_obj_item_id numeric(20,0) NOT NULL,
  obj_obj_item_id numeric(20,0) NOT NULL,
  obj_item_assoc_ix numeric(20,0) NOT NULL,
  obj_item_assoc_stat_ix numeric(20,0) NOT NULL,

CONSTRAINT obj_item_assoc_stat_pkey PRIMARY KEY (subj_obj_item_id, obj_obj_item_id, obj_item_assoc_ix, obj_item_assoc_stat_ix),

CONSTRAINT obj_item_assoc_stat_subj_obj_item_id_fkey FOREIGN KEY (subj_obj_item_id, obj_obj_item_id, obj_item_assoc_ix) REFERENCES obj_item_assoc (subj_obj_item_id, obj_obj_item_id, obj_item_assoc_ix) )



@Entity
@Table(name = "obj_item_assoc_stat")
@IdClass(ObjectItemAssociationStatus.ObjectItemAssociationStatusId.class)
public class ObjectItemAssociationStatus extends LoggableEntity {

    @Id
@Column(name = "obj_item_assoc_stat_ix", nullable = false, length = 20)
    protected BigInteger ix;

    @Id
    @ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "subj_obj_item_id", nullable = false, updatable = false)
    protected ObjectItem subjObjItem;

    @Id
    @ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "obj_obj_item_id", nullable = false, updatable = false)
    protected ObjectItem objObjItem;

    @Id
    @ManyToOne(fetch = FetchType.EAGER)
@JoinColumns({@JoinColumn(name = "subj_obj_item_id", referencedColumnName = "subj_obj_item_id", nullable = false), @JoinColumn(name = "obj_obj_item_id", referencedColumnName = "obj_obj_item_id", nullable = false), @JoinColumn(name = "obj_item_assoc_ix", referencedColumnName = "obj_item_assoc_ix", nullable = false)})
    protected ObjectItemAssociation objItemAssoc;
. . . }

@Entity
@Table(name = "obj_item_assoc")
@IdClass(ObjectItemAssociation.ObjectItemAssociationId.class)
public class ObjectItemAssociation extends NonIndependentEntity {

    @Id
    @Column(name = "obj_item_assoc_ix", nullable = false, length = 20)
    protected BigInteger ix;

    @Id
    @ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "subj_obj_item_id", nullable = false, updatable = false)
    protected ObjectItem subjObjItem;

    @Id
    @ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "obj_obj_item_id", nullable = false, updatable = false)
    protected ObjectItem objObjItem;
. . . }


--
Christopher
twitter: @fakod
blog: http://blog.fakod.eu


------------------------------------------------------------------------

_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top