今天做价格策略,报如下异常:
org.springframework.orm.hibernate3.HibernateObjectRetrievalFailureException: No row with the given identifier exists
查了下,发现我的Model是这样写的:
@ManyToOne(fetch = FetchType.EAGER , targetEntity=TProductType.class) @JoinColumn(name = "PRODUCT_NUM", unique=true, nullable = false, insertable = false, updatable = false) public TProductType getProductType() { return productType; } @ManyToOne(fetch = FetchType.EAGER, targetEntity=TCommissionType.class) @JoinColumn(name = "TYPE_NUM",nullable = false, insertable = false, updatable = false) public TCommissionType getCommissionType() { return commissionType; }
其中productType和commissionType映射为联合主键(分别为PRODUCT_NUM、TYPE_NUM),分别从TProductType表、TCommission表引用主键。
一种策略对应1W中产品,即TYPE_NUM是可以重复了,但是映射时候unique = true,错误!!!
1.@JoinColumn(name = "TYPE_NUM")必须去掉unique = true。
2.targetEntity=TCommissionType.class,必须有,否则映射不到实体。