こんにちは皆さん、私は冬眠するのが初めてです。休止状態関連のトピックのスタックオーバーフローをサーフィンしているときに、これを見つけました
ソリューションを読んだ後、私は少し混乱し、Oracle 11g データベースを使用した多対 1 の背後にある実際のメカニズムを理解するための正確なシナリオの構築を開始しました。プロジェクトの休止状態を実行しているとき、テーブルと 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])
私が言及した上記のトピックの解決策を正確に実行しました。エンティティクラスを投稿しています。これを解決するのを手伝ってください
クラスジョブ
@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)
(時間を節約するために3つのクラスに同じシーケンスを使用しました)、次に
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);
データが他のテーブルに挿入される前にジョブテーブルに挿入されたため、例外が発生したと思います。私が欠けているものを見つけるのを手伝ってください。