我有一個Hibernate映射,休眠實體映射空對象
@Entity
@Table(name="user")
public class User{
@ManyToOne(optional=true)
@JoinColumn(name="email_id",nullable=true)
private Email email;
}
在我的地圖,電子郵件對象將是空的時候。由於email_id和email字段不爲空,因此我想只在User表中插入,如果對象爲null,則需要跳過電子郵件表。我如何處理這種情況?
org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing
如果我使用@ManyToOne(cascade=CascadeType.ALL), am getting null exception
。
請幫助我,在此先感謝
不,我需要這個電子郵件對象分開,我不能在用戶對象內使用這個,因爲有時候電子郵件對象將被插入。 – user1335605
@ user1335605,我不是說你要保留'user'中的所有屬性。只要將'email_id'保留爲'user'屬性。 – Amogh