ejb@glassfish.java.net

Re: _at_Embeddable class

From: Eve Pokua <gorgeous65_at_msn.com>
Date: Wed, 20 Jun 2007 12:05:50 +0100

Hello Markus,

I have tried following your suggestion No.2 to resolve my composite key
issue.

I was looking at the JEE 5 tutorial example of order:

javaeetutorial5\examples\ejb\order\order-ejb\src\java\order\entity

The LineItemKey which is the IdClass states the hashCode method

public int hashCode() {
        return (((this.getOrderId() == null) ? 0 : this.getOrderId()
                                                       .hashCode())
        ^ ((int) this.getItemId()));
    }

which must be override.

Infact this example of the tutorial is more or less what I am trying to
achieve.

In my IdClass, i override the hashCode as follows:

public int hashCode() {
        return (((this.getcollOrdID() == null) ? 0 : this.getcollOrdID()
                                                    .hashCode()));

    }

I would like a little bit of explanation of hashCode if possible.

Secondly I get the following errors during deployment:


Exception Description: The annotated
element
[private StockInformation.Iteamdetailsent
StockInformation.Iteamdetailsent.iteamdetailsent]
has an unsupported collection type
[class StockInformation.Iteamdetailsent].
Only Set, List, Map and Collection are supported.



Exception Description: The attribute
[collOrdersrement] in entity class
[class StockInformation.Customerent]
has a mappedBy value of [collOrdersrement]
which does not exist in its owning entity
class [class StockInformation.CollOrdersrement].
If the owning entity class is a
@MappedSuperclass, this is invalid,
and your attribute should reference
the correct subclass.



Exception Description: The attribute
[iteamdetailsent] in entity class
[class StockInformation.Iteamdetailsent]
has a mappedBy value of [collOrdersrement]
which does not exist in its owning entity
class [class StockInformation.Iteamdetailsent]
. If the owning entity class is a
@MappedSuperclass, this is invalid, and your
attribute should reference the correct
subclass.



I got rid of them by using getting rid of the mappings.


Then I get the following:

Deploying application in domain failed; Exception [TOPLINK-0] (Oracle
TopLink Essentials - 2006.8 (Build 060830)):
oracle.toplink.essentials.exceptions.IntegrityException
Descriptor Exceptions:
---------------------------------------------------------
Exception [TOPLINK-46] (Oracle TopLink Essentials - 2006.8 (Build 060830)):
oracle.toplink.essentials.exceptions.DescriptorException
Exception Description: There should be one non-read-only
mapping defined for the primary key field [COLLPOINTORDERLINE.CollORDID].
Descriptor: RelationalDescriptor(StockInformation.CollOrdline -->
[DatabaseTable(COLLPOINTORDERLINE)])
Runtime Exceptions:
---------------------------------------------------------
C:\jee\STOCKINFOR2\nbproject\build-impl.xml:187: Deployment error:
The module has not been deployed.
See the server log for details.
BUILD FAILED (total time: 21 seconds)


Server log:


Exception [TOPLINK-46] (Oracle TopLink Essentials - 2006.8 (Build 060830)):
oracle.toplink.essentials.exceptions.DescriptorException
Exception Description: There should be one non-read-only mapping defined for
the primary key field [COLLPOINTORDERLINE.CollORDID].
Descriptor: RelationalDescriptor(StockInformation.CollOrdline -->
[DatabaseTable(COLLPOINTORDERLINE)])

Runtime Exceptions:
---------------------------------------------------------

        at
oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:240)
        at
oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:78)
        at
oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:113)
        at
oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:107)
        at
oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:76)
        at
com.sun.jdo.spi.persistence.support.ejb.ejbc.PersistenceProcessor.loadPersistenceUnitBundle(PersistenceProcessor.java:468)
        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)
|#]

I believe it is referring to my composite key entity which contains the
code:


@IdClass(StockInformation.CollOrdlinementKey.class)

@Entity

@Table(name="COLLPOINTORDERLINE")

public class CollOrdline implements java.io.Serializable{

        private String itmid;
        private String cusid;
        private String collOrdID;

        public CollOrdline(){}


    @Id
    public String getitmid(){
                return itmid;}

    public void setitmid(String itmid){
                this.itmid=itmid;}

    @Id
    @Column(name = "CollORDID", nullable = false, insertable = false,
updatable = false)
    public String getcollOrdID(){
                return collOrdID;}

    public void setcollOrdID(String collOrdID){
                this.collOrdID=collOrdID;}


    @Id
    public String getcusid()
   {return cusid;}

   public void setcusid(String cusid){
       this.cusid=cusid;
   }



}


I'm not sure if I have state my relationships properly and if I'm on the
right track.

Please, do not hesitate to ask for more details.

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/

_________________________________________________________________
Tell Hotmail about an email that changed your life!
http://www.emailbritain.co.uk/