大家好我是新的休眠。而我是衝浪的休眠相關主題的堆棧溢出,我發現這個關於使用休眠映射對象到數據庫
Need clarification about mapping objects to database, annotations, and one to many relationships
閱讀解決方案,我有點迷茫後開始建設的具體情況,瞭解多對一背後的實際機制,我在哪裏使用Oracle 11g數據庫。當我運行我的項目Hibernate是自動生成的表和FK的關係,而且在插入數據時就面臨這樣的問題(這是顯而易見的)
WARN: HHH000437: Attempting to save one or more entities that have a non-nullable association with an unsaved transient entity. The unsaved transient entity must be saved in an operation prior to saving these dependent entities.
Unsaved transient entity: ([com.entity.Authorization#0])
Dependent entities: ([[com.entity.Job#1]])
WARN: HHH000437: Attempting to save one or more entities that have a non-nullable association with an unsaved transient entity. The unsaved transient entity must be saved in an operation prior to saving these dependent entities.
Unsaved transient entity: ([com.entity.JobFilteration#0])
Dependent entities: ([[com.entity.Job#1]])
Non-nullable association(s): ([com.entity.Job.jobfilteration])
我做了什麼是上述專題我的解決辦法剛纔提到,我張貼我的實體類(S)請幫我解決這個
類工作
@Entity
@Table(name="JOB")
public class Job implements Serializable {
@Id
@SequenceGenerator(name="person_seq", sequenceName="SEQ_PERSON",initialValue=1,allocationSize=1)
@GeneratedValue(strategy = GenerationType.SEQUENCE ,generator="person_seq")
@Column(name="JOB_SERIAL")
private int id;
@Column(name="JOB_CATAGORY",nullable=false,length=200,unique=true)
private String catagory;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn (name="JOB_AUTHID", nullable = false, updatable = false, insertable = false)
private Authorization authorization;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn (name="JOB_JOBFILTERID", nullable = false, updatable = false, insertable = false)
private JobFilteration jobfilteration;
類JobFilteration
@Entity
@Table(name="JOB_FILTERATION")
public class JobFilteration implements Serializable {
@Id
@SequenceGenerator(name="person_seq", sequenceName="SEQ_PERSON",initialValue=1,allocationSize=1)
@GeneratedValue(strategy = GenerationType.SEQUENCE ,generator="person_seq")
@Column(name="FILTER_SERIAL")
private int id;
@Column(name="FILTERNAME",nullable=false,length=200)
private String filtername;
類授權
@Entity
@Table(name="AUTHORIZATION")
public class Authorization implements Serializable {
@Id
@SequenceGenerator(name="person_seq", sequenceName="SEQ_PERSON",initialValue=1,allocationSize=1)
@GeneratedValue(strategy = GenerationType.SEQUENCE ,generator="person_seq")
@Column(name="AUTH_ID")
private int id;
@Column(name="AUTHORISEDBY",nullable=false,length=200)
private String authorisedby;
和用於插入我寫的方法public void insertToDB(Job job)
的數據(我使用相同的序列爲三類,以節省時間),然後
JoBDao jobdao= new JoBDao();
Job job= null;
Authorization auth = null;
JobFilteration jfilter = null;
try{
job= new Job();
auth = new Authorization();
auth.setAuthorisedby("SOMEPERSON");
jfilter = new JobFilteration();
jfilter.setFiltername("JEE");
job.setCatagory("PERMANENT");
job.setAuthorization(auth);
job.setJobfilteration(jfilter);
jobdao.addPersonandCard(job);
我認爲發生異常是因爲數據在插入其他表之前插入到作業表中。請幫我找出我錯過了什麼?
我每天值有填補,現在我已經提交了所有的類,請看看 – NaN