Hello Eve,
You should really clean up the code as it is very difficult to see what
you have tried and what is currently causing the problem with so much
code commented out. I can't see what you are trying to accomplish when the
//_at_EmbeddedId
//private OrdlinementKey ordlinementKey;
is commented out, as is the OrdlinementKey's //_at_Embeddable annotation.
You also have a floating @EmbeddedId annotation in OrdlinementKey
complete with attribute overrides that seem to float on the toString
method.
If you are just trying to use many-to-one relationships in your primary
key, if you are using the latest EclipseLink build you can use the new
Derived Id JPA 2.0 feature. This allows you to mark the @ManyToOne
relations with the @Id tag and just get rid of the extra EmbeddedId or
basic mappings. ie:
@IdClass(stockInformation.OrdlinementKey.class)
@Entity
@Table(name="ORDERLINE")
public class Ordlineent implements Serializable {
@Id
@ManyToOne(cascade = {CascadeType.ALL})
@JoinColumn(name="ORDID")
private Orderent orderent;
@ManyToOne(cascade = {CascadeType.ALL})
@JoinColumn(name="ITMID")
private Iteamdetailsent iteamdetailsent;
@ManyToOne(cascade = {CascadeType.ALL})
@JoinColumn(name="CUSID")
private Customerent customerent;
}
Your Id class would need to change slightly just to reflect that the
attribute names need to be orderent, iteamdetailsent and customerent
instead of ordID etc. ie:
public class OrdlinementKey implements java.io.Serializable{
private Long orderent;
private Long customerent;
private Long orderent;
}
Regards,
Chris
Eve Pokua wrote:
> Thanks Gordon,
>
> I've attached the files. yes, i did get the errors but i corrected
> it before
> delying again. but in the tables, i've multiples.
>
> thanks
>
> eve
>
> ------------------------------------------------------------------------
> Date: Fri, 27 Feb 2009 09:30:16 -0400
> From: gordon.yorke_at_oracle.com
> To: persistence_at_glassfish.dev.java.net
> Subject: Re: @IdClass issues
>
> I would have to see your code. In TopLink I would expect a multiple
> writable mapping exception if you had multiple mappings that wrote to
> the same field.
> --Gordon
>
> Eve Pokua wrote:
>
> Thanks Gordon.
>
> Using Embeddable & embeddedId works. i can deploy this. however,
> attributes are writing twice in the tables of the database. how
> do i resolve this?
> I thought I could resolve it with attributesoverrides but it does
> not work.
>
> Any help on EmbeddId?
>
> Thanks
>
> eve
>
> ------------------------------------------------------------------------
> Date: Thu, 26 Feb 2009 11:29:07 -0400
> From: gordon.yorke_at_oracle.com <mailto:gordon.yorke_at_oracle.com>
> To: persistence_at_glassfish.dev.java.net
> <mailto:persistence_at_glassfish.dev.java.net>
> Subject: Re: @IdClass issues
>
> In the source that was attached to your previous email the cusid
> attribute of the Key was commented out.
> --Gordon
>
> Eve Pokua wrote:
>
> Gordon,
>
> which class? The Orderl/inementkey does contain the cusid:/
> //
> /Please be specific. I understand it's may be something small
> which I/
> /can't see./
> //
> /thanks eve/
> //
> package stockInformation;
> public class OrdlinementKey implements java.io.Serializable{
> private static final long serialVersionUID = 1L;
> private Long itmid;
> private Long cusid;
> private Long ordID;
>
> public OrdlinementKey(){}
>
>
> public Long getItmid(){
> return itmid;}
> public void setItmid(Long itmid){
> this.itmid=itmid;}
> public Long getCusid()
> {return cusid;}
> public void setCusid(Long cusid){
> this.cusid=cusid;
> }
> public Long getOrdID(){
> return ordID;}
> public void setOrdID(Long ordID){
> this.ordID=ordID;}
>
> @Override
> public int hashCode() {
> if (this. getOrdID() == null || this.getItmid() ==
> null) {
> return 0;
> } else {
> return (this. getOrdID().hashCode() ^
> this.getItmid().hashCode());
> }
> }
> @Override
> public boolean equals(Object obj) {
> if (obj == null) {
> return false;
> }
> if (getClass() != obj.getClass()) {
> return false;
> }
> final OrdlinementKey other = (OrdlinementKey) obj;
> if (this.itmid != other.itmid && (this.itmid == null
> || !this.itmid.equals(other.itmid))) {
> return false;
> }
> if (this.cusid != other.cusid && (this.cusid == null
> || !this.cusid.equals(other.cusid))) {
> return false;
> }
> if (this.ordID != other.ordID && (this.ordID == null
> || !this.ordID.equals(other.ordID))) {
> return false;
> }
> return true;
> }
>
> }
>
> -----------------------------------------------------------
>
>
> --------------------------------------------------------------
>
>
> @IdClass(stockInformation.OrdlinementKey.class)
> @Entity
> @Table(name="ORDERLINE")
> public class Ordlineent implements Serializable {
> private static final long serialVersionUID = 1L;
> @Id
> @Column(name = "ITEMID", nullable = false,
> insertable=false, updatable=false)
> private Long itmid;
> @Id
> @Column(name = "CUSID", nullable = false,
> insertable=false, updatable=false)
> private Long cusid;
> @Id
> @Column(name = "ORDID", nullable = false,
> insertable=false, updatable=false)
> private Long ordID;
>
>
> @ManyToOne(cascade = {CascadeType.ALL})
> @JoinColumn(name="ORDID")
> private Orderent orderent;
> @ManyToOne(cascade = {CascadeType.ALL})
> @JoinColumn(name="ITEMID")
> private Iteamdetailsent iteamdetailsent;
> @ManyToOne(cascade = {CascadeType.ALL})
> @JoinColumn(name="CUSID")
> private Customerent customerent;
> @Column(name="QUANTITY", nullable=true)
> private Long quanity;
>
> public Long getItmid(){
> return itmid;}
> public void setItmid(Long itmid){
> this.itmid=itmid;}
>
> public Long getCusid()
> {return cusid;}
> public void setCusid(Long cusid){
> this.cusid=cusid;
> }
>
> public Long getOrdID(){
> return ordID;}
> public void setOrdID(Long ordID){
> this.ordID=ordID;}
>
>
> public Orderent getOrderent() {
> return orderent;
> }
> public void setOrderent(Orderent orderent) {
> this.orderent = orderent;
> }
> public Iteamdetailsent getIteamdetailsent() {
> return iteamdetailsent;
> }
> public void setIteamdetailsent(Iteamdetailsent
> iteamdetailsent) {
> this.iteamdetailsent = iteamdetailsent;
> }
> public Customerent getCustomerent() {
> return customerent;
> }
> public void setCustomerent(Customerent customerent) {
> this.customerent = customerent;
> }
> public Long getQuanity() {
> return quanity;
> }
> public void setQuanity(Long quanity) {
> this.quanity = quanity;
> }
> @Override
> public String toString() {
> return "stockInformation.Ordlineent[id=" + itmid + "]";
> }
> }
>
>
> -----------------------------
>
> Thanks eve
>
> ------------------------------------------------------------------------
> Date: Wed, 25 Feb 2009 22:40:25 -0400
> From: gordon.yorke_at_oracle.com <mailto:gordon.yorke_at_oracle.com>
> To: persistence_at_glassfish.dev.java.net
> <mailto:persistence_at_glassfish.dev.java.net>
> CC: users_at_glassfish.dev.java.net
> <mailto:users_at_glassfish.dev.java.net>;
> ejb_at_glassfish.dev.java.net <mailto:ejb_at_glassfish.dev.java.net>
> Subject: Re: @IdClass issues
>
> Your PKClass is missing the cusID
> --Gordon
>
> Eve Pokua wrote:
>
> Hello everyone,
>
> I am having problems creating an IdClass. I get the
> following errors:
>
> [#|2009-02-26T00:06:06.435+0000|SEVERE|sun-appserver9.1|javax.enterprise.system.tools.deployment|_ThreadID=38;_ThreadName=Thread-127;_RequestID=01812ccb-53b3-4d7e-bafe-5a688d407eb3;|Exception
> occured in J2EEC Phase
> com.sun.enterprise.deployment.backend.IASDeploymentException:
> Exception [TOPLINK-28018] (Oracle TopLink Essentials - 2.0
> (Build b58g-fcs (09/07/2007))):
> oracle.toplink.essentials.exceptions.EntityManagerSetupException
> Exception Description: predeploy for PersistenceUnit
> [STOCKINFOR2-ejbPU] failed.
> Internal Exception: Exception [TOPLINK-7150] (Oracle
> TopLink Essentials - 2.0 (Build b58g-fcs (09/07/2007))):
> oracle.toplink.essentials.exceptions.ValidationException
> Exception Description: Invalid composite primary key
> specification. The names of the primary key fields or
> properties in the primary key class
> [stockInformation.OrdlinementKey] and those of the entity
> bean class [class stockInformation.Ordlineent] must
> correspond and their types must be the same. Also, ensure
> that you have specified id elements for the corresponding
> attributes in XML and/or an @Id on the corresponding
> fields or properties of the entity class.
> at
> oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:643)
> at
> oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.createContainerEntityManagerFactory(EntityManagerFactoryProvider.java:244)
> at
> com.sun.jdo.spi.persistence.support.ejb.ejbc.PersistenceProcessor.loadPersistenceUnitBundle(PersistenceProcessor.java:512)
> at
> com.sun.jdo.spi.persistence.support.ejb.ejbc.PersistenceProcessor.createTablesInDB(PersistenceProcessor.java:353)
> at
> com.sun.jdo.spi.persistence.support.ejb.ejbc.PersistenceProcessor.processAppBundle(PersistenceProcessor.java:219)
> at
> com.sun.jdo.spi.persistence.support.ejb.ejbc.PersistenceProcessor.processApplication(PersistenceProcessor.java:146)
> at
> com.sun.jdo.spi.persistence.support.ejb.ejbc.DeploymentEventListenerImpl.processApplication(DeploymentEventListenerImpl.java:211)
> at
> com.sun.jdo.spi.persistence.support.ejb.ejbc.DeploymentEventListenerImpl.processEvent(DeploymentEventListenerImpl.java:172)
> at
> com.sun.jdo.spi.persistence.support.ejb.ejbc.DeploymentEventListenerImpl.notifyDeploymentEvent(DeploymentEventListenerImpl.java:122)
> at
> com.sun.enterprise.deployment.backend.DeploymentEventManager.notifyDeploymentEvent(DeploymentEventManager.java:79)
> at
> com.sun.enterprise.deployment.backend.AppDeployer.postDeploy(AppDeployer.java:392)
> at
> com.sun.enterprise.deployment.backend.AppDeployer.deploy(AppDeployer.java:251)
> at
> com.sun.enterprise.deployment.backend.AppDeployer.doRequestFinish(AppDeployer.java:148)
> at
> com.sun.enterprise.deployment.phasing.J2EECPhase.runPhase(J2EECPhase.java:191)
> at
> com.sun.enterprise.deployment.phasing.DeploymentPhase.executePhase(DeploymentPhase.java:108)
> at
> com.sun.enterprise.deployment.phasing.PEDeploymentService.executePhases(PEDeploymentService.java:919)
> at
> com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:279)
> at
> com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:788)
> at
> com.sun.enterprise.management.deploy.DeployThread.deploy(DeployThread.java:187)
> at
> com.sun.enterprise.management.deploy.DeployThread.run(DeployThread.java:223)
> |#]
>
> I have attached the files for your convenience. As you
> may notice, I have been
> messing around with it trying to get it right.
> Orderlineent is the entity of the breakdown of many to many
> relationship for Order & Items and Customer. So
> Orderlineent does not have and Id of it's own that's why
> I need the IdClass.
>
> Please, help. I can't figure out why this error and can't
> deploy it.
>
> Thanks
>
> eve
>
>
> ------------------------------------------------------------------------
> Share your photos with Windows Live Photos - Free Try it
> Now!
> <http://www.microsoft.com/uk/windows/windowslive/products/messenger.aspx>
>
>
> ------------------------------------------------------------------------
> Share your photos with Windows Live Photos - Free Try it Now!
> <http://www.microsoft.com/uk/windows/windowslive/products/messenger.aspx>
>
>
> ------------------------------------------------------------------------
> Windows Live Hotmail just got better. Find out more!
> <http://www.microsoft.com/uk/windows/windowslive/products/hotmail.aspx>
>
>
> ------------------------------------------------------------------------
> Share your photos with Windows Live Photos – Free Find out more!
> <http://clk.atdmt.com/UKM/go/132630768/direct/01/>