Hello Markus,
Thank you for your reply. I believe the suggestion you made below is what i
am trying to achieve:
You don't need any IdClass or such, just specify the join table
COLLECTPOINTORDERS for the relationship by using the @JoinTable annotation
(spec, 9.1.25 JoinTable Annotation). The table COLLECTPOINTORDERS must not
be mapped to an entity.
2) If COLLECTPOINTORDERS *does have* attributes besides the foreign keys to
CUSTOMER and ITEMS (e.g. ShippingDate, or such), you will need three entity
classes to model your problem: Customerent, Itemdetailent, and
CollOrdersrement. The (bi-directional) relationships are
a) Customerent OneToMany CollOrdersrement
CollOrdersrement ManyToOne Customerent
b) CollOrdersrement ManyToOne Itemdetailent
Itemdetailent OneToMany CollOrdersrement
CollOrdersrement needs to define an IdClass, having the attributes
CustomerId and ItemId. Both relationships will be owned by CollOrdersrement
and the relationship fields should be mapped as UPDATABLE=false, as they are
defined by setting the primary key.
Please let us know if you have further questions.
I will try and have a go with this and update you on this.
Thanks
eve
>From: Markus Fuchs <Markus.Fuchs_at_Sun.COM>
>Reply-To: persistence_at_glassfish.dev.java.net
>To: persistence_at_glassfish.dev.java.net
>Subject: Re: @Embeddable class
>Date: Mon, 18 Jun 2007 09:57:47 -0700
>
>Hi Eve -
>
>1) If COLLECTPOINTORDERS doesn't have any attributes besides the foreign
>keys to CUSTOMER and ITEMS, you can have the (bi-directional) relationship
>mapped as
>
>Customerent ManyToMany Itemdetailsent
>Itemdetailsent ManyToMany Customerent
>
>You don't need any IdClass or such, just specify the join table
>COLLECTPOINTORDERS for the relationship by using the @JoinTable annotation
>(spec, 9.1.25 JoinTable Annotation). The table COLLECTPOINTORDERS must not
>be mapped to an entity.
>
>2) If COLLECTPOINTORDERS *does have* attributes besides the foreign keys
>to CUSTOMER and ITEMS (e.g. ShippingDate, or such), you will need three
>entity classes to model your problem: Customerent, Itemdetailent, and
>CollOrdersrement. The (bi-directional) relationships are
>
>a) Customerent OneToMany CollOrdersrement
>CollOrdersrement ManyToOne Customerent
>b) CollOrdersrement ManyToOne Itemdetailent
>Itemdetailent OneToMany CollOrdersrement
>
>CollOrdersrement needs to define an IdClass, having the attributes
>CustomerId and ItemId. Both relationships will be owned by CollOrdersrement
>and the relationship fields should be mapped as UPDATABLE=false, as they
>are defined by setting the primary key.
>
>Please let us know if you have further questions.
>
>-- markus.
>
>Eve Pokua wrote:
>>Thank you Marina,
>>
>>>Can you explain in more details what are you trying to accomplish?
>>
>>For each entity below: I have the associated tables.
>>
>>@Entity
>>@Table(name="CUSTOMER")
>>public class Customerent implements Serializable {
>>
>>...............
>>}
>>
>>
>>
>>---------------------------------------------------------------------------
>>
>>
>>
>>@Entity
>>@Table(name="ITEMS")
>>
>>
>>
>>public class Iteamdetailsent implements Serializable{
>>
>>
>>
>>.........}
>>
>>
>>
>>------------------------------------------------------------------------------------
>>
>>
>>
>>
>>@Entity
>>@Table(name="COLLECTPOINTORDERS")
>>
>>public class CollOrdersrement implements java.io.Serializable{
>>
>>......................................................}
>>
>>----------------------------------------------------------------------------------
>>
>>
>>
>>Now in CollOrdersrement entity, I have to map a manytomany relationship
>>of:
>>
>>Iteamdetailsent ------------>CollOrdersrement
>>
>>
>>Customerent ----------------------------->CollOrdersrement
>>
>>meaning:
>>
>>
>>Items----------------------> Order
>>Customer--------------------->Order
>>
>>An Order can have many items
>>a customer can have many orders.
>>
>>Now since these are many to many relationships, I thought I could achieve
>>by using
>>Embeddable/EmbeddID or IdClass to create a composite keys in it on table.
>>
>>To create a composite relationship, I need an extra table like:
>>
>>COLLPOINTORDERLINE
>>
>>which would have relationships of:
>>
>>Customer to Order
>>
>>and
>>
>>Order to Items
>>
>>
>>I hope I have explain myself clearly. Now if I can't use EmbeddableId or
>>IdClass. Now if I can't achieve this by these, then I guess I have to
>>read more on persistence.
>>
>>Any suggestions would be appreciated.
>>
>>Thanks
>>
>>eve
>>
>>
>>>From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
>>>Reply-To: persistence_at_glassfish.dev.java.net
>>>To: persistence_at_glassfish.dev.java.net
>>>CC: ejb_at_glassfish.dev.java.net
>>>Subject: Re: @Embeddable class
>>>Date: Fri, 15 Jun 2007 16:59:05 -0700
>>>
>>>Eve,
>>>
>>>Can you explain in more details what are you trying to accomplish? What
>>>does it mean to have a PK (Embedded or not) mapped to its own table?
>>>
>>>Now my thoughts on your example: it shouldn't matter whether it's an
>>>EmbeddedId or an IdClass, but the spec doesn't support relationship
>>>fields in either of them, so you are at the persistence provider mercy to
>>>support such mapping.
>>>
>>>thanks,
>>>-marina
>>>
>>>Eve Pokua wrote:
>>>>
>>>>So if I wanted this embeddable class as a table as well within my
>>>>Database,
>>>>I'm I better off using @IdClass than embeddable?
>>>>
>>>>Thanks
>>>>
>>>>eve
>>>>
>>>>>From: Cheng Fang <Cheng.Fang_at_Sun.COM>
>>>>>Reply-To: ejb_at_glassfish.dev.java.net
>>>>>To: ejb_at_glassfish.dev.java.net
>>>>>Subject: Re: @Embeddable class
>>>>>Date: Thu, 14 Jun 2007 13:47:00 -0400
>>>>>
>>>>>One thing that stands out is, Embeddable class doesn't have persistence
>>>>>identity so don't use @Table annotation on the embeddable class.
>>>>>
>>>>>The stacktrace doesn't seem to show the root cause.
>>>>>
>>>>>A simple example of using @Embeddable and @EmbeddedId (from Java
>>>>>Persistence spec). Refer to the spec for more details:
>>>>>
>>>>>@Entity
>>>>>public class Employee {
>>>>>@EmbeddedId public EmployeePK getEmpPK() { ... }
>>>>>...
>>>>>}
>>>>>
>>>>>
>>>>>@Embeddable
>>>>>public class EmployeePK {
>>>>>String name;
>>>>>Date bday;
>>>>>}
>>>>>
>>>>>-cheng
>>>>>
>>>>>Eve Pokua wrote:
>>>>>
>>>>>>Hello everyone,
>>>>>>
>>>>>>I have 3 entity classes:
>>>>>>
>>>>>>@Entity
>>>>>>@Table(name="CUSTOMER")
>>>>>>public class Customerent implements Serializable {
>>>>>>........................
>>>>>>
>>>>>>.........................}
>>>>>>
>>>>>>
>>>>>>---------------------------------------------------------------------------------------------------------------
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>@Entity
>>>>>>@Table(name="ITEMS")
>>>>>>
>>>>>>..................
>>>>>>
>>>>>>public class Iteamdetailsent implements Serializable{
>>>>>>.............................
>>>>>>.............................
>>>>>>.............................}
>>>>>>
>>>>>>
>>>>>>
>>>>>>---------------------------------------------------------------------------------------------------------------
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>@Entity
>>>>>>@Table(name="COLLECTPOINTORDERS")
>>>>>>
>>>>>>public class CollOrdersrement implements java.io.Serializable{
>>>>>>
>>>>>>......................................................}
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>----------------------------------------------------------------------------------------------
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>I am trying to make all these classed into composite keys, so I
>>>>>>created an embeddable class as follows:
>>>>>>
>>>>>>package StockInformation;
>>>>>>import java.util.Collection;
>>>>>>import java.util.List;
>>>>>>import javax.ejb.*;
>>>>>>import javax.persistence.Column;
>>>>>>import javax.persistence.Embeddable;
>>>>>>import javax.persistence.Entity;
>>>>>>import javax.persistence.Id;
>>>>>>import javax.persistence.JoinColumn;
>>>>>>import javax.persistence.ManyToMany;
>>>>>>import javax.persistence.ManyToOne;
>>>>>>import javax.persistence.OneToMany;
>>>>>>import javax.persistence.Table;
>>>>>>
>>>>>>
>>>>>>@Embeddable
>>>>>>@Table(name="COLLPOINTORDERLINE")
>>>>>>
>>>>>>public class CollOrdlinementPK implements java.io.Serializable{
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> @JoinColumn(name="itmid")
>>>>>>
>>>>>> private Iteamdetailsent iteamdetailsent;
>>>>>>
>>>>>>
>>>>>> @JoinColumn(name="cusid")
>>>>>> @ManyToOne
>>>>>> private Customerent customerent;
>>>>>>
>>>>>> @JoinColumn(name="collOrdID")
>>>>>> @ManyToOne
>>>>>> private CollOrdersrement collOrdersrement;
>>>>>>
>>>>>>
>>>>>>}
>>>>>>
>>>>>>
>>>>>>
>>>>>>I get the following errors:
>>>>>>
>>>>>>[#|2007-06-14T10:02:14.312+0100|SEVERE|sun-appserver-pe9.0|javax.enterprise.system.tools.deployment|_ThreadID=16;_ThreadName=Thread-36;_RequestID=14698a97-5f07-4767-89d2-9d7c3a0538b7;|Exception
>>>>>>occured in J2EEC Phase
>>>>>>com.sun.enterprise.deployment.backend.IASDeploymentException
>>>>>> at java.util.AbstractList$Itr.next(AbstractList.java:427)
>>>>>> at
>>>>>>oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataDescriptor.getPrimaryKeyFieldName(MetadataDescriptor.java:494)
>>>>>>
>>>>>>
>>>>>>
>>>>>> at
>>>>>>oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.ObjectAccessor.processOneToOneForeignKeyRelationship(ObjectAccessor.java:107)
>>>>>>
>>>>>>
>>>>>>
>>>>>> at
>>>>>>oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.ObjectAccessor.processOwningMappingKeys(ObjectAccessor.java:92)
>>>>>>
>>>>>>
>>>>>>
>>>>>> at
>>>>>>oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.ManyToOneAccessor.process(ManyToOneAccessor.java:73)
>>>>>>
>>>>>>
>>>>>>
>>>>>> at
>>>>>>oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.RelationshipAccessor.processRelationship(RelationshipAccessor.java:250)
>>>>>>
>>>>>>
>>>>>>
>>>>>> at
>>>>>>oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataProject.processRelationshipDescriptors(MetadataProject.java:513)
>>>>>>
>>>>>>
>>>>>>
>>>>>> at
>>>>>>oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataProject.process(MetadataProject.java:445)
>>>>>>
>>>>>>
>>>>>>
>>>>>> at
>>>>>>oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataProcessor.processAnnotations(MetadataProcessor.java:203)
>>>>>>
>>>>>>
>>>>>>
>>>>>> at
>>>>>>oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl.processORMetadata(EntityManagerSetupImpl.java:993)
>>>>>>
>>>>>>
>>>>>>
>>>>>> at
>>>>>>oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:501)
>>>>>>
>>>>>>
>>>>>>
>>>>>> at
>>>>>>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.createContainerEntityManagerFactory(EntityManagerFactoryProvider.java:152)
>>>>>>
>>>>>>
>>>>>>
>>>>>> at
>>>>>>com.sun.jdo.spi.persistence.support.ejb.ejbc.PersistenceProcessor.loadPersistenceUnitBundle(PersistenceProcessor.java:467)
>>>>>>
>>>>>>
>>>>>>
>>>>>> at
>>>>>>com.sun.jdo.spi.persistence.support.ejb.ejbc.PersistenceProcessor.createTablesInDB(PersistenceProcessor.java:325)
>>>>>>
>>>>>>
>>>>>>
>>>>>> at
>>>>>>com.sun.jdo.spi.persistence.support.ejb.ejbc.PersistenceProcessor.processAppBundle(PersistenceProcessor.java:190)
>>>>>>
>>>>>>
>>>>>>
>>>>>> at
>>>>>>com.sun.jdo.spi.persistence.support.ejb.ejbc.PersistenceProcessor.processApplication(PersistenceProcessor.java:125)
>>>>>>
>>>>>>
>>>>>>
>>>>>> at
>>>>>>com.sun.jdo.spi.persistence.support.ejb.ejbc.DeploymentEventListenerImpl.processApplication(DeploymentEventListenerImpl.java:193)
>>>>>>
>>>>>>
>>>>>>
>>>>>> at
>>>>>>com.sun.jdo.spi.persistence.support.ejb.ejbc.DeploymentEventListenerImpl.processEvent(DeploymentEventListenerImpl.java:152)
>>>>>>
>>>>>>
>>>>>>
>>>>>> at
>>>>>>com.sun.jdo.spi.persistence.support.ejb.ejbc.DeploymentEventListenerImpl.notifyDeploymentEvent(DeploymentEventListenerImpl.java:109)
>>>>>>
>>>>>>
>>>>>>
>>>>>> at
>>>>>>com.sun.enterprise.deployment.backend.DeploymentEventManager.notifyDeploymentEvent(DeploymentEventManager.java:66)
>>>>>>
>>>>>>
>>>>>>
>>>>>> at
>>>>>>com.sun.enterprise.deployment.backend.AppDeployer.postDeploy(AppDeployer.java:429)
>>>>>>
>>>>>>
>>>>>>
>>>>>> at
>>>>>>com.sun.enterprise.deployment.backend.AppDeployer.deploy(AppDeployer.java:225)
>>>>>>
>>>>>>
>>>>>>
>>>>>> at
>>>>>>com.sun.enterprise.deployment.backend.AppDeployer.doRequestFinish(AppDeployer.java:129)
>>>>>>
>>>>>>
>>>>>>
>>>>>> at
>>>>>>com.sun.enterprise.deployment.phasing.J2EECPhase.runPhase(J2EECPhase.java:169)
>>>>>>
>>>>>>
>>>>>>
>>>>>> at
>>>>>>com.sun.enterprise.deployment.phasing.DeploymentPhase.executePhase(DeploymentPhase.java:95)
>>>>>>
>>>>>>
>>>>>>
>>>>>> at
>>>>>>com.sun.enterprise.deployment.phasing.PEDeploymentService.executePhases(PEDeploymentService.java:871)
>>>>>>
>>>>>>
>>>>>>
>>>>>> at
>>>>>>com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:266)
>>>>>>
>>>>>>
>>>>>>
>>>>>> at
>>>>>>com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:739)
>>>>>>
>>>>>>
>>>>>>
>>>>>> at
>>>>>>com.sun.enterprise.management.deploy.DeployThread.deploy(DeployThread.java:174)
>>>>>>
>>>>>>
>>>>>>
>>>>>> at
>>>>>>com.sun.enterprise.management.deploy.DeployThread.run(DeployThread.java:210)
>>>>>>
>>>>>>
>>>>>>
>>>>>>|#]
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>Bearing in mind this is my first time of Embeddable classes, what am I
>>>>>>doing wrong?
>>>>>>
>>>>>>Thanks
>>>>>>
>>>>>>eve
>>>>>>
>>>>>>_________________________________________________________________
>>>>>>Play your part in making history - Email Britain!
>>>>>>http://www.emailbritain.co.uk/
>>>>>>
>>>>>>---------------------------------------------------------------------
>>>>>>To unsubscribe, e-mail: ejb-unsubscribe_at_glassfish.dev.java.net
>>>>>>For additional commands, e-mail: ejb-help_at_glassfish.dev.java.net
>>>>>>
>>>>>
>>>>>---------------------------------------------------------------------
>>>>>To unsubscribe, e-mail: ejb-unsubscribe_at_glassfish.dev.java.net
>>>>>For additional commands, e-mail: ejb-help_at_glassfish.dev.java.net
>>>>>
>>>>
>>>>_________________________________________________________________
>>>>Play your part in making history - Email Britain!
>>>>http://www.emailbritain.co.uk/
>>
>>_________________________________________________________________
>>The next generation of Hotmail is here! http://www.newhotmail.co.uk/
_________________________________________________________________
Txt a lot? Get Messenger FREE on your mobile.
https://livemessenger.mobile.uk.msn.com/