我有一个雇主表用含有userprofileId休眠:无法对象被包含已保存对象
雇主表模式的参考时如所陈述如下含有userprofileid其是使用JPA保存对象用户表中的主键
id int(11) (not NULL) PRI
userprofileid int(11) (not nUll)
organization_name varchar(50) (not nUll)
现在我的要求是为这个雇主创建一个JPA类。
现在我们有Employer.java,下面输入。
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@OneToOne(fetch=FetchType.LAZY,cascade = CascadeType.ALL)
@JoinColumn(name="userProfileId", referencedColumnName="id")
@Column(insertable=false ,updatable =false)
private UserProfile userProfile;
@Column(name = "organization_name")
private String organizationName;
现在的障碍是。 我们的UserProfile对象是以不同的方法创建的。现在我不想再为userprofile表添加相同的值,所以我在employer.java中使insertable = false和updatable = false,以便字段不会更新;
没有,如果我设置USERPROFILE的雇主对象的值
它说
org.springframework.dao.InvalidDataAccessApiUsageException: detached entity passed to persist: com.hcentive.core.user.UserProfile; nested exception is org.hibernate.PersistentObjectException: detached entity passed to persist: com.hcentive.core.user.UserProfile
,但如果我不设置用户配置文件它给下面的错误。
Caused by: java.sql.SQLException: Field 'userprofileid' doesn't have a default value
注以用于存留我使用:
getJpaTemplate().persist(t);