【发布时间】:2013-01-25 07:06:47
【问题描述】:
我对 Hibernate 非常陌生,在这里我遇到了一个瞬态异常。请帮忙。
保存对象时发生异常Location 对象引用了一个未保存的--transient 实例 - 在刷新之前保存瞬态实例:<City object>; nested exception is org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing
当我尝试将数据保存到我的位置表中时,我遇到了异常,该位置表有一个 City 对象,其所有元素都指向 null。
Location object
private String LocationAddress;
@ManyToOne
@JoinColumn(name = "CITYID")
private City city;
City
private String cityName;
private int cityId;
在位置表中CityID 是可为空的字段,因为city 不是必填字段。我们有一个城市表,它是一个静态表,所以我们不想在城市表中插入数据。
现在当我们存储 Location 对象时。如果 City 对象具有某些值(例如某个城市),则它可以很好地存储数据。但是当对象包含空白对象时抛出异常(cityName 和cityId 为空)
请帮忙。
示例场景
Successful
Location
locationAddress = "test Address"
city
cityId="1"
cityName="testCity"
Failure
Location
locationAddress = "test Address"
city
cityId=null
cityName=null
【问题讨论】: