我已經編寫了一個應用程序,該應用程序使用jaxb解析xml文檔,然後使用JPA插入到數據庫中。JPA One to One實體 - 無法插入
我有三個JPA實體。
1.ItemEntity 2.PromotionEntity 3.SellPriceEntity
該項目的實體具有與PromotionEntity並與SellPrice Entitiy以一對一的關係的一對一的關係。
當嘗試只使用ItemEntity插入數據庫時,我的應用程序工作並且將項目記錄插入到數據庫中。但是,當我嘗試使用ItemEntity,PromotionEntity和SellPriceEntity插入數據庫時,我開始出現錯誤。
org.apache.openjpa.persistence.PersistenceException:錯誤的整數值:'\ xAC \ xED \ x00 \ x05sr \ x00,org.apache.camel.example.etl.PromotionEntity $ \ x0C \ xF5 \ xF1 \ x08 \ x0B \ xA2 \ x81 \ x02 \ x00 \ x05L \ x00 \ x02idt \ x00 \ x10'列1中的列'PROMOTION_ID'{prepstmnt 1554452939 INSERT INTO item(id,ATTRIBUTE_1,ATTRIBUTE_3,ATTRIBUTE_2,BRAND_LOGO_FILE_NAME,BRAND_NAME,CLASS_NO, DEFAULT_MARGIN,說明,EXTENDED_DESCRIPTION,EXTENDED_DESCRIPTION_2,GST_CODE,映像文件名,ITEM_NO,OUT_OF_STOCK_IND,PACK_QTY,PROMOTION_ID,SELL_PRICE_ID,SELLING_UNIT,SIZE_APPLICABLE,STOCK_AVAILABLE,SPPLR_NO,體積,WEB_AGE_GROUP,WEB_COLOR_DESCRIPTION,WEB_DESCRIPTION,WEB_SIZE_DESCRIPTION,WEIGHT)VALUES(?,?,?, ,?,?,?,?,?,?,?,?,?,?,?,?,?,?,? } [code = 1366,state = HY000] FailedObject:org.apache.camel.example .etl.ItemEntity @ 333f8b4c
這裏是我如何設定我的實體bean起來......
@Entity(name = "item")
public class ItemEntity implements java.io.Serializable {
private static final long serialVersionUID = -9063279672222036437L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "ITEM_NO")
private String itemNo;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name="PROMOTION_ID")
private PromotionEntity promotion;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name="SELL_PRICE_ID")
private SellPriceEntity sellPrice;
gets and sets...
促進實體
@Entity(name = "promotion")
public class PromotionEntity implements java.io.Serializable {
private static final long serialVersionUID = 2597721500656837249L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "PROMOTION_ID")
private String promotionId;
@Column(name = "PROMOTION_PRICE")
private String promotionPrice;
gets and sets...
售價實體
@Entity(name = "sell_price")
public class SellPriceEntity implements java.io.Serializable {
private static final long serialVersionUID = -205334787672950850L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "SELL_PRICE_EFFECTIVE_DATE_1")
private String sellPriceEffectiveDateOne;
@Column(name = "SELL_PRICE_1")
private String sellPriceOne;
gets and sets...
我相信我已經正確定義了關係字段,因此不確定發生了什麼問題。在試圖通過JDBCStoreManager類調試,我可以看到正在執行的SQL是....
INSERT INTO item (
id,
ATTRIBUTE_1,
ATTRIBUTE_3,
ATTRIBUTE_2,
BRAND_LOGO_FILE_NAME,
BRAND_NAME,
CLASS_NO,
DEFAULT_MARGIN,
DESCRIPTION,
EXTENDED_DESCRIPTION,
EXTENDED_DESCRIPTION_2,
GST_CODE, I
MAGE_FILE_NAME,
ITEM_NO,
OUT_OF_STOCK_IND,
PACK_QTY,
PROMOTION_ID,
SELL_PRICE_ID,
SELLING_UNIT,
SIZE_APPLICABLE,
STOCK_AVAILABLE,
SPPLR_NO,
VOLUME,
WEB_AGE_GROUP,
WEB_COLOR_DESCRIPTION,
WEB_DESCRIPTION,
WEB_SIZE_DESCRIPTION,
WEIGHT)
VALUES (701, '', '', '', '', '', '350', '.00', 'KHOMBU APFOOTA KOKO HIGH', '', '', '1', '', '93501250080', 'Y', '0', ** STREAM DATA **, ** STREAM DATA **, 'Each', 'Y', '0', 'KHOMBU', '.0000', '', 'Black', '', '8', '.00')
在那裏我應該將promotion_id和sell_price_id它告訴我** STREAM DATA **。是對的嗎?也許這就是我得到一個數據類型錯誤的原因。
感謝
嘗試使用'@Column(name =「PROMOTION_ID」,referencedColumnName =「InsertColumnJoinHere」)' – nachokk