我有两个休眠的映射类:
SETTLEMENT_MODEL_GROUP(父级):
@Entity
@Table(name = "MODEL_GROUP")
public class SettlementModelGroup
{
//omitted some not fields
@OneToMany( fetch = FetchType.LAZY, mappedBy = "modelGroup" )
private List<SettlementModel> settlementModels;
}
SETTLEMENT_MODEL孩子:
@Entity
@Table(name = "MODEL")
public class SettlementModel
{
//omitted some not fields
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "MODEL_GROUP_ID", insertable = false, updatable = false, nullable = false)
private SettlementModelGroup modelGroup;
}
现在我正在对数据库进行简单的插入:
SettlementModel model = new SettlementModel();
SettlementModelGroup settlementModelGroup = modelManager.getModelGroup( modelGroupId );
//setting other fields for model
model.setModelGroup( settlementModelGroup );
sessionFactory.getCurrentSession().save( model );
给我:
SQL Error: 1400, SQLState: 23000
ORA-01400: cannot insetr NULL into ("MYSCHEMA"."MODEL"."MODEL_GROUP_ID")
为什么休眠不插入父 ID,尽管它存在并被创建?即使在标准输出上给出它也会返回正确的 ID ...
此外,我无法insertable = false, updatable = false
从SettlementModel中删除,因为它在部署期间给了我休眠错误