我编写了一个应用程序,它使用 jaxb 解析 xml 文档,然后使用 JPA 插入数据库。
我有三个 JPA 实体。
1.ItemEntity 2.PromotionEntity 3.SellPriceEntity
item 实体与 PromotionEntity 具有一对一的关系,与 SellPrice Entity 具有一对一的关系。
当尝试仅使用 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,image_file_name,item_no,out_of_stock_stock_ind,pack_qty,pack_qty,calling_price_id,sell_price_id,salking_unit,size_applicable,size_applicable,stock_applicable,stock_available,spec_available,spplr_no,spplr_no,spplr_no,web_age_group? ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)} [code= 1366,状态=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 是....
com.mysql.jdbc.JDBC4PreparedStatement@6d66cc49:
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 **。那正确吗?也许这就是我收到数据类型错误的原因。
谢谢