-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate/JPA(Bug) DB table generation issue
PostPosted: Fri Jul 29, 2011 3:37 am 
Newbie

Joined: Fri Jul 29, 2011 3:25 am
Posts: 1
I developed couple of entity classes as attached(StockTransferOutCarton.java, StockTransferOutTask.java, StockTransferOutItem.java).
When I start the application, the JPA create the tables automatically(stock_transfer_out_carton, stock_transfer_out_task, stock_transfer_out_item), however, the table, stock_transfer_out_carton creates a strange foreign key, stock_transfer_out_carton_id, which is not mentioned in StockTransferOutCarton.java entity class). The generated creation script for table, stock_transfer_out_carton is shown as below. Please see the following script especially the line in red.

mysql> show create table stock_transfer_out_carton;
+---------------------------+----------------------------------------------------------------------------------------------------------------------
| Table | Create Table
+---------------------------+----------------------------------------------------------------------------------------------------------------------
| stock_transfer_out_carton | CREATE TABLE `stock_transfer_out_carton` (
`stock_transfer_out_carton_id` int(11) NOT NULL AUTO_INCREMENT,
`carton_name` varchar(255) NOT NULL,
`status` int(11) NOT NULL,
`stock_transfer_out_task_id` int(11) NOT NULL,
PRIMARY KEY (`stock_transfer_out_carton_id`),
KEY `FK6880853BA1C36BED` (`stock_transfer_out_carton_id`),
KEY `FK6880853BC895A2A7` (`stock_transfer_out_task_id`),
CONSTRAINT `FK6880853BC895A2A7` FOREIGN KEY (`stock_transfer_out_task_id`) REFERENCES `stock_transfer_out_task` (`stock_transfer_out_task_id`),
CONSTRAINT `FK6880853BA1C36BED` FOREIGN KEY (`stock_transfer_out_carton_id`) REFERENCES `stock_transfer_out_task` (`stock_transfer_out_task_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+---------------------------+----------------------------------------------------------------------------------------------------------------------
1 row in set (0.00 sec)

Why it generated the two strange lines?

Code:
package com.masterson.mics.model;



import java.util.List;



import javax.persistence.Column;

import javax.persistence.Entity;

import javax.persistence.GeneratedValue;

import javax.persistence.Id;

import javax.persistence.JoinColumn;

import javax.persistence.ManyToOne;

import javax.persistence.OneToMany;

import javax.persistence.Table;



import org.apache.commons.lang.builder.ReflectionToStringBuilder;

import org.apache.commons.lang.builder.ToStringStyle;



@Entity

@Table(name = "stock_transfer_out_carton")

public class StockTransferOutCarton {



   @Id

   @Column(name="stock_transfer_out_carton_id")

   @GeneratedValue

   protected Integer stockTransferOutCartonId; 

   

   @ManyToOne

   @JoinColumn(name = "stock_transfer_out_task_id",  nullable = false)

   protected StockTransferOutTask stockTransferOutTaskId;

   

   @Column(name="carton_name",  nullable = false)

   protected String cartonName;

   

   @Column(name="status", length=3,  nullable = false)

   protected Integer status;

   

   @OneToMany(mappedBy = "stockTransferOutCartonId")

   List<StockTransferOutItem> item;



   public Integer getStockTransferOutCartonId() {

      return stockTransferOutCartonId;

   }



   public void setStockTransferOutCartonId(Integer stockTransferOutCartonId) {

      this.stockTransferOutCartonId = stockTransferOutCartonId;

   }



   public StockTransferOutTask getStockTransferOutTaskId() {

      return stockTransferOutTaskId;

   }



   public void setStockTransferOutTaskId(StockTransferOutTask stockTransferOutTaskId) {

      this.stockTransferOutTaskId = stockTransferOutTaskId;

   }



   public String getCartonName() {

      return cartonName;

   }



   public void setCartonName(String cartonName) {

      this.cartonName = cartonName;

   }



   public Integer getStatus() {

      return status;

   }



   public void setStatus(Integer status) {

      this.status = status;

   }



   public List<StockTransferOutItem> getItem() {

      return item;

   }



   public void setItem(List<StockTransferOutItem> item) {

      this.item = item;

   }



   public StockTransferOutCarton() {

      super();

   }



   public StockTransferOutCarton(Integer stockTransferOutCartonId) {

      super();

      this.stockTransferOutCartonId = stockTransferOutCartonId;

   }

   

   public StockTransferOutCarton(StockTransferOutTask stockTransferOutTaskId) {

      super();

      this.stockTransferOutTaskId = stockTransferOutTaskId;

   }



   public StockTransferOutCarton(Integer stockTransferOutCartonId, StockTransferOutTask stockTransferOutTaskId) {

      super();

      this.stockTransferOutCartonId = stockTransferOutCartonId;

      this.stockTransferOutTaskId = stockTransferOutTaskId;

   }



   public StockTransferOutCarton(Integer stockTransferOutCartonId, StockTransferOutTask stockTransferOutTaskId,

         String cartonName, Integer status, List<StockTransferOutItem> item) {

      super();

      this.stockTransferOutCartonId = stockTransferOutCartonId;

      this.stockTransferOutTaskId = stockTransferOutTaskId;

      this.cartonName = cartonName;

      this.status = status;

      this.item = item;

   }



   @Override

   public String toString() {

      return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);

   }

   

}

Code:
package com.masterson.mics.model;



import java.util.Date;



import javax.persistence.Column;

import javax.persistence.Entity;

import javax.persistence.GeneratedValue;

import javax.persistence.Id;

import javax.persistence.JoinColumn;

import javax.persistence.ManyToOne;

import javax.persistence.Table;



import org.apache.commons.lang.builder.ReflectionToStringBuilder;

import org.apache.commons.lang.builder.ToStringStyle;





@Entity

@Table(name = "stock_transfer_out_item")

public class StockTransferOutItem {



   @Id

   @Column(name = "stock_transfer_out_item_id")

   @GeneratedValue

   protected Integer stockTransferOutItemId;

   

   @ManyToOne

   @JoinColumn(name = "stock_transfer_out_carton_id",  nullable = false)

   protected StockTransferOutCarton stockTransferOutCartonId;

   

   @ManyToOne

   @JoinColumn(name = "session_id",  nullable = false)

   protected Session sessionId;

   

   @Column(name = "item_no",  nullable = false)

   protected String itemNo;

   

   @Column(name = "ean_code",  nullable = false)

   protected String eanCode;

   

   @Column(name = "color")

   protected String color;

   

   @Column(name = "size")

   protected String size;



   @Column(name = "quantity",  nullable = false)

   protected Integer quantity;

   

   @Column(name = "sequence_no",  nullable = false)

   protected Integer sequenceNo;

   

   @Column(name = "type",  nullable = false)

   protected Integer type;

   

   @Column(name = "hht_create_date")

   protected Date hhtCreateDate;

   

   @Column(name = "create_date",  nullable = false)

   protected Date createDate;



   public Integer getStockTransferOutItemId() {

      return stockTransferOutItemId;

   }



   public void setStockTransferOutItemId(Integer stockTransferOutItemId) {

      this.stockTransferOutItemId = stockTransferOutItemId;

   }



   public StockTransferOutCarton getStockTransferOutCartonId() {

      return stockTransferOutCartonId;

   }



   public void setStockTransferOutCartonId(StockTransferOutCarton stockTransferOutCartonId) {

      this.stockTransferOutCartonId = stockTransferOutCartonId;

   }



   public Session getSessionId() {

      return sessionId;

   }



   public void setSessionId(Session sessionId) {

      this.sessionId = sessionId;

   }



   public String getItemNo() {

      return itemNo;

   }



   public void setItemNo(String itemNo) {

      this.itemNo = itemNo;

   }



   public String getEanCode() {

      return eanCode;

   }



   public void setEanCode(String eanCode) {

      this.eanCode = eanCode;

   }



   public String getColor() {

      return color;

   }



   public void setColor(String color) {

      this.color = color;

   }



   public String getSize() {

      return size;

   }



   public void setSize(String size) {

      this.size = size;

   }



   public Integer getQuantity() {

      return quantity;

   }



   public void setQuantity(Integer quantity) {

      this.quantity = quantity;

   }



   public Integer getSequenceNo() {

      return sequenceNo;

   }



   public void setSequenceNo(Integer sequenceNo) {

      this.sequenceNo = sequenceNo;

   }



   public Integer getType() {

      return type;

   }



   public void setType(Integer type) {

      this.type = type;

   }



   public Date getHhtCreateDate() {

      return hhtCreateDate;

   }



   public void setHhtCreateDate(Date hhtCreateDate) {

      this.hhtCreateDate = hhtCreateDate;

   }



   public Date getCreateDate() {

      return createDate;

   }



   public void setCreateDate(Date createDate) {

      this.createDate = createDate;

   }



   public StockTransferOutItem() {

      super();

   }

   

   public StockTransferOutItem(Integer stockTransferOutItemId, StockTransferOutCarton stockTransferOutCartonId,

         Session sessionId, String itemNo, String eanCode, String color, String size, Integer quantity,

         Integer sequenceNo, Integer type, Date hhtCreateDate, Date createDate) {

      super();

      this.stockTransferOutItemId = stockTransferOutItemId;

      this.stockTransferOutCartonId = stockTransferOutCartonId;

      this.sessionId = sessionId;

      this.itemNo = itemNo;

      this.eanCode = eanCode;

      this.color = color;

      this.size = size;

      this.quantity = quantity;

      this.sequenceNo = sequenceNo;

      this.type = type;

      this.hhtCreateDate = hhtCreateDate;

      this.createDate = createDate;

   }

   

   @Override

   public String toString() {

      return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);

   }



}

Code:
package com.masterson.mics.model;



import java.util.Date;

import java.util.List;



import javax.persistence.Column;

import javax.persistence.Entity;

import javax.persistence.GeneratedValue;

import javax.persistence.Id;

import javax.persistence.JoinColumn;

import javax.persistence.ManyToOne;

import javax.persistence.OneToMany;

import javax.persistence.Table;



import org.apache.commons.lang.builder.ReflectionToStringBuilder;

import org.apache.commons.lang.builder.ToStringStyle;



@Entity

@Table(name = "stock_transfer_out_task")

public class StockTransferOutTask {



   @Id

   @Column(name="stock_transfer_out_task_id")

   @GeneratedValue

   protected Integer stockTransferOutTaskId;

   

   @Column(name = "delivery_note_no", length = 45, unique= true, nullable = false   )

   protected String deliveryNoteNo;

   

   @ManyToOne

   @JoinColumn(name = "batch_id")

   protected Batch batchId;

   

   @ManyToOne

   @JoinColumn(name = "session_id", nullable = false)

   protected Session sessionId;

   

   @ManyToOne

   @JoinColumn(name = "from_location_id")

   protected Location fromLocationId;



   @ManyToOne

   @JoinColumn(name = "to_location_id")

   protected Location toLocationId;

   

   @Column(name = "status", nullable = false, length=3)

   protected Integer status;

   

   @Column(name = "hht_submit_date", nullable=true)

   protected Date handsetSubmitDate;

   

   @Column(name = "hht_create_date")

   protected Date handsetCreatedate;

   

   @Column(name = "create_date", nullable = false)

   protected Date createDate;



   @Column(name = "last_modify_date", nullable = false)

   protected Date lastModifyDate;



   @OneToMany(mappedBy = "stockTransferOutCartonId")

   List<StockTransferOutCarton> carton;

   

   public Integer getStockTransferOutTaskId() {

      return stockTransferOutTaskId;

   }



   public void setStockTransferOutTaskId(Integer stockTransferOutTaskId) {

      this.stockTransferOutTaskId = stockTransferOutTaskId;

   }



   public String getDeliveryNoteNo() {

      return deliveryNoteNo;

   }



   public void setDeliveryNoteNo(String deliveryNoteNo) {

      this.deliveryNoteNo = deliveryNoteNo;

   }



   public Batch getBatchId() {

      return batchId;

   }



   public void setBatchId(Batch batchId) {

      this.batchId = batchId;

   }



   public Session getSessionId() {

      return sessionId;

   }



   public void setSessionId(Session sessionId) {

      this.sessionId = sessionId;

   }



   public Location getFromLocationId() {

      return fromLocationId;

   }



   public void setFromLocationId(Location fromLocationId) {

      this.fromLocationId = fromLocationId;

   }



   public Location getToLocationId() {

      return toLocationId;

   }



   public void setToLocationId(Location toLocationId) {

      this.toLocationId = toLocationId;

   }



   public Integer getStatus() {

      return status;

   }



   public void setStatus(Integer status) {

      this.status = status;

   }



   public Date getHandsetSubmitDate() {

      return handsetSubmitDate;

   }



   public void setHandsetSubmitDate(Date handsetSubmitDate) {

      this.handsetSubmitDate = handsetSubmitDate;

   }



   public Date getHandsetCreatedate() {

      return handsetCreatedate;

   }



   public void setHandsetCreatedate(Date handsetCreatedate) {

      this.handsetCreatedate = handsetCreatedate;

   }



   public Date getCreateDate() {

      return createDate;

   }



   public void setCreateDate(Date createDate) {

      this.createDate = createDate;

   }



   public Date getLastModifyDate() {

      return lastModifyDate;

   }



   public void setLastModifyDate(Date lastModifyDate) {

      this.lastModifyDate = lastModifyDate;

   }



   public List<StockTransferOutCarton> getCarton() {

      return carton;

   }



   public void setCarton(List<StockTransferOutCarton> carton) {

      this.carton = carton;

   }



   public StockTransferOutTask() {

      super();

   }



   public StockTransferOutTask(Integer stockTransferOutTaskId) {

      super();

      this.stockTransferOutTaskId = stockTransferOutTaskId;

   }



   public StockTransferOutTask(Integer stockTransferOutTaskId, String deliveryNoteNo, Batch batchId,

         Session sessionId, Location fromLocationId, Location toLocationId, Integer status, Date handsetSubmitDate,

         Date handsetCreatedate, Date createDate, Date lastModifyDate, List<StockTransferOutCarton> carton) {

      super();

      this.stockTransferOutTaskId = stockTransferOutTaskId;

      this.deliveryNoteNo = deliveryNoteNo;

      this.batchId = batchId;

      this.sessionId = sessionId;

      this.fromLocationId = fromLocationId;

      this.toLocationId = toLocationId;

      this.status = status;

      this.handsetSubmitDate = handsetSubmitDate;

      this.handsetCreatedate = handsetCreatedate;

      this.createDate = createDate;

      this.lastModifyDate = lastModifyDate;

      this.carton = carton;

   }



   @Override

   public String toString() {

      return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);

   }

   

}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.