【发布时间】:2015-10-28 06:40:27
【问题描述】:
我正在尝试使用 hibernate 保存嵌套对象,我收到 could not execute statement; SQL [n/a] Exception
代码
@Entity
@Table(name = "listing")
@Inheritance(strategy = InheritanceType.JOINED)
public class Listing implements Serializable {
@Id
@Column(name = "listing_id")
private String listingId;
@Column(name = "property_type")
private PropertyType propertyType;
@Column(name = "category")
private Category category;
@Column(name = "price_currency")
private String priceCurrency;
@Column(name = "price_value")
private Double priceValue;
@Column(name = "map_point")
private MapPoint mapPoint;
@Column(name = "commission_fee_info")
private CommissionFeeInfo commissionFeeInfo;
}
public class MapPoint implements Serializable {
private final float latitude;
private final float longitude;
}
public class CommissionFeeInfo implements Serializable {
private String agentFeeInfo;
private CommissionFeeType commissionFeeType;
private Double value;
private Double commissionFee;
}
public enum CommissionFeeType implements Serializable { }
使用RazorSQL 我看到hibernate 将MapPoint 和CommissionFee 定义为VARBINARY
我无法理解的是,当commissionFeeInfo 不存在时,hibernate 设法保存它。保存MapPoint没有问题
有人知道我做错了什么吗?
更新
我发现如果CommissionFeeInfo的所有属性除了agentFeeInfo都是null,那么对象将被保存而没有问题。如果其他属性之一是!= null,则会发生错误。
更新 2
我把CommissionFeeInfo的所有属性的类型都改成了String,对象就可以正常保存了,但是我不能让属性为String。
【问题讨论】:
-
你能解释更多你遇到的错误吗?有没有嵌套异常?任何 SQL 错误代码?
-
@RicardoVila 是的,有一个嵌套异常
java.sql.SQLDataException: data exception: string data, right truncation; table: LISTING column: COMMISSION_FEE_INFO -
还有
org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.DataException: could not execute statement和sql = n/a
标签: java hibernate exception save hsqldb