0 Replies Latest reply on Mar 27, 2008 4:37 AM by venuwin

    EJB3 creates the foreign keys twice

    venuwin

      Hi,

      I have one table named "Orders" and the corresponding Entity is Order.java which is given below. When i deploy the application, i am able to see the foreign keys created twice and also the indices to those FK colmns are created twice.

      What am i doing wrong ?

      Entity class :



      import static javax.persistence.CascadeType.ALL;
      import java.io.Serializable;
      import java.util.Collection;
      import java.util.Date;
      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.GeneratedValue;
      import javax.persistence.GenerationType;
      import javax.persistence.Id;
      import javax.persistence.JoinColumn;
      import javax.persistence.ManyToOne;
      import javax.persistence.NamedQueries;
      import javax.persistence.NamedQuery;
      import javax.persistence.OneToMany;
      import javax.persistence.OneToOne;
      import javax.persistence.Table;
      import javax.persistence.TableGenerator;

      @Entity
      @Table(name = "orders")
      @NamedQueries( {
      @NamedQuery(name = "net.abc.app.ejb.entities.updateOrderStatus", query = "Update Order o set o.status=:status,o.finalOrderStatus=:finalStatus WHERE o.orderId = :orderId "),
      @NamedQuery(name = "net.abc.app.ejb.entities.updateOrderRemarks", query = "Update Order o set o.remarks=:remarks WHERE o.orderId = :orderId "),
      @NamedQuery(name = "net.abc.app.ejb.entities.updateMailStatus", query = "Update Order o set o.mailStatus=:status,o.sendStatusMailToadmin=:mailToDesk WHERE o.orderId = :orderId "),
      @NamedQuery(name = "net.abc.app.ejb.entities.getOrderRemarks", query = "SELECT o.remarks FROM Order o where o.orderId = :orderId"),
      @NamedQuery(name = "net.abc.app.ejb.entities.getOrderIds", query = "SELECT o.orderId FROM Order o where o.status=:status and o.actualOrder=:actual"),
      @NamedQuery(name = "net.abc.app.ejb.entities.updateActualOrderStatus", query = "Update Order o set o.actualOrder=:actual,o.status=:status,o.finalOrderStatus=:finalStatus WHERE o.orderId = :orderId ")
      })
      public class Order implements Serializable {

      private Long orderId;
      private Date orderDate;
      private Date shippingDate;
      private String recipientFirstName;
      private String recipientLastName;
      private String recipientPhone;
      private String recipientEmail;
      private String recipientCompany;
      private String giftMessage;
      private String customerId;
      private boolean selectionType;
      private Customer customer;
      private String status;//Fetch Price/Pending/Success/Failed,Partial success
      private String remarks;
      private boolean mailStatus;
      private boolean isActualOrder;
      private OrderAddress orderAddress;
      private Brands branding;
      private Integer brandId;
      //field to identify failed order status mail to order desk or customer
      private boolean sendStatusMailToadmin;
      private String orderStatusXML;
      private String shippingType;
      private String finalOrderStatus;//Success/Failes Partial success
      private String appVersion;
      private Collection items;
      private Collection orderPrice;
      private CollectionvendorOrderStatus;

      public boolean isSendStatusMailToadmin() {
      return sendStatusMailToadmin;
      }

      public void setSendStatusMailToadmin(boolean sendStatusMailToCustomer) {
      this.sendStatusMailToadmin = sendStatusMailToCustomer;
      }

      public boolean isMailStatus() {
      return mailStatus;
      }

      public void setMailStatus(boolean mailStatus) {
      this.mailStatus = mailStatus;
      }


      public Order() {
      super();

      }

      public Order(Long orderid) {
      this.orderId = orderid;

      }
      //mappedBy to indicate that this is the inverse
      //side of the bidirectional relation.
      @OneToMany(cascade = ALL, mappedBy = "order")
      public Collection getItems() {
      return items;
      }

      public void setItems(Collection items) {
      this.items = items;
      }


      public String getGiftMessage() {
      return giftMessage;
      }

      public void setGiftMessage(String message) {
      this.giftMessage = message;
      }

      @Column(nullable = false)
      public Date getOrderDate() {
      return orderDate;
      }

      public void setOrderDate(Date orderDate) {
      this.orderDate = orderDate;
      }

      @Column(name = "customerid")
      public String getCustomerId() {
      return customerId;
      }

      public void setCustomerId(String customerId) {
      this.customerId = customerId;
      }

      @ManyToOne
      @JoinColumn(name = "customerid",referencedColumnName="customerid",insertable=false,updatable=false)
      public Customer getCustomer() {
      return customer;
      }

      public void setCustomer(Customer customer) {
      this.customer = customer;
      }
      @TableGenerator(
      name="orderKeysGen",
      table="abc_sequence_generator",
      pkColumnName="GEN_KEY",
      valueColumnName="GEN_VALUE",
      pkColumnValue="orderId",
      allocationSize=1
      )
      @Id
      @GeneratedValue(strategy=GenerationType.TABLE,
      generator="orderKeysGen")
      /*@Id
      @GeneratedValue*/
      public Long getOrderId() {
      return orderId;
      }

      public void setOrderId(Long orderId) {
      this.orderId = orderId;
      }


      //@Column(nullable = false)
      public String getRecipientEmail() {
      return recipientEmail;
      }

      public void setRecipientEmail(String recipientEmail) {
      this.recipientEmail = recipientEmail;
      }

      @Column(nullable = false)
      public String getRecipientFirstName() {
      return recipientFirstName;
      }

      public void setRecipientFirstName(String recipientFirstName) {
      this.recipientFirstName = recipientFirstName;
      }

      public String getRecipientLastName() {
      return recipientLastName;
      }

      public void setRecipientLastName(String recipientLastName) {
      this.recipientLastName = recipientLastName;
      }

      @Column(nullable = false)
      public String getRecipientPhone() {
      return recipientPhone;
      }

      public void setRecipientPhone(String recipientPhone) {
      this.recipientPhone = recipientPhone;
      }

      @Column(nullable = false)
      public boolean isSelectionType() {
      return selectionType;
      }

      public void setSelectionType(boolean selectionType) {
      this.selectionType = selectionType;
      }

      // @Column(nullable = false)
      public Date getShippingDate() {
      return shippingDate;
      }

      public void setShippingDate(Date shippingDate) {
      this.shippingDate = shippingDate;
      }

      public void addLineItem(LineItem lineItem) {
      this.getItems().add(lineItem);
      }

      @Column(nullable = false)
      public String getStatus() {
      return status;
      }

      public void setStatus(String status) {
      this.status = status;
      }

      @Column(columnDefinition="TEXT")
      public String getRemarks() {
      return remarks;
      }

      public void setRemarks(String remarks) {
      this.remarks = remarks;
      }

      public String getRecipientCompany() {
      return recipientCompany;
      }

      public void setRecipientCompany(String recipientCompany) {
      this.recipientCompany = recipientCompany;
      }
      @OneToOne(cascade=ALL,mappedBy="order")
      public OrderAddress getOrderAddress() {
      return orderAddress;
      }

      public void setOrderAddress(OrderAddress orderAddress) {
      this.orderAddress = orderAddress;
      }

      /**
      * @return the brandId
      */
      @Column(name = "brandId")
      public Integer getBrandId() {
      return brandId;
      }

      /**
      * @param brandId the brandId to set
      */
      public void setBrandId(Integer brandId) {
      this.brandId = brandId;
      }

      /**
      * @return the branding
      */
      @ManyToOne
      @JoinColumn(name = "brandid",insertable=false)
      public Brands getBranding() {
      return branding;
      }

      /**
      * @param branding the branding to set
      */
      public void setBranding(Brands branding) {
      this.branding = branding;
      }

      public boolean isActualOrder() {
      return isActualOrder;
      }

      public void setActualOrder(boolean isFinalPhase) {
      this.isActualOrder = isFinalPhase;
      }
      @Column(columnDefinition="TEXT")
      public String getOrderStatusXML() {
      return orderStatusXML;
      }

      public void setOrderStatusXML(String statusXML) {
      this.orderStatusXML = statusXML;
      }

      public String getShippingType() {
      return shippingType;
      }

      public void setShippingType(String shippingType) {
      this.shippingType = shippingType;
      }
      @OneToMany(cascade = ALL, mappedBy = "order")
      public Collection getOrderPrice() {
      return orderPrice;
      }

      public void setOrderPrice(Collection orderPrice) {
      this.orderPrice = orderPrice;
      }
      @OneToMany(cascade = ALL, mappedBy = "order")
      public Collection getVendorOrderStatus() {
      return vendorOrderStatus;
      }

      public void setVendorOrderStatus(Collection vendorOrderStatus) {
      this.vendorOrderStatus = vendorOrderStatus;
      }

      public String getvendorOrderStatus(String vendorId){

      for(VendorOrderStatus vos:vendorOrderStatus){
      if(vos.getVendorId().equals(vendorId)){
      return vos.getStatusMessage();
      }
      }
      //if vendor status not available return null;
      return null;
      }
      /**
      *
      * Status updated by admin .
      */
      public String getFinalOrderStatus() {
      return finalOrderStatus;
      }

      public void setFinalOrderStatus(String finalOrderStatus) {
      this.finalOrderStatus = finalOrderStatus;
      }

      public String getAppVersion() {
      return appVersion;
      }

      public void setAppVersion(String appVersion) {
      this.appVersion = appVersion;
      }

      }


      THanks in advance