我正在使用Hibernate向數據庫中插入一行,我使用Visual Paradigm(Enterprise Edition)來生成數據庫表。通過hibernate映射插入數據到數據庫表失敗
下面是錯誤
org.orm.PersistentException:org.hibernate.PropertyValueException: 非空屬性引用null或瞬時值: com.patientmanagement.model.Patient.visitRecord在 org.orm.PersistentSession.saveOrUpdate(PersistentSession.java:631)在 org.orm.PersistentManager.saveObject(PersistentManager.java:287)在 com.patientmanagement.model.PatientDAO.save(PatientDAO.java:303)在 com.test.InsertData.main(InsertData.java:28)引起者: org.hibernate.Prope rtyValueException:在 org.hibernate.event com.patientmanagement.model.Patient.visitRecord在 org.hibernate.engine.Nullability.checkNullability(Nullability.java:100) :非空屬性引用 null或瞬態值.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:312) 在 org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:203) 在 org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener .java:129) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener。的java:210) 在 org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195) 在 org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:117) 在 有機.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93) 在 org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:687) 在org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl。 java:679) at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:675) at org.orm.PersistentSession.saveOrUpdate(PersistentSession的.java:629) ... 3個
這裏是插入函數測試
public class InsertData {
public static void main(String[]args) throws PersistentException
{
PersistentTransaction trans=PatientmanagementPersistentManager.instance().getSession().beginTransaction();
try
{
//create patient instance
Patient patient=PatientDAO.createPatient();
//set patients properties
patient.setName("Markus Rosevelt");
patient.setRegisterDate(new Date());
//save patient
PatientDAO.save(patient);
trans.commit();
}catch(Exception e){
trans.rollback();
}
}
}
請提供映射 – kommradHomer 2012-04-06 09:29:22