spring - Saving owned/child objects in Hibernate -


I have a hard time wrapping my head around the hibernate object work here is a small part of what my model looks like :

JobOpening:

  @ManyToMany (speed = FetchType.EAGER, cascade = CascadeType.ALL) @JoinTable (name = "jobOpening_questionSet", joinColumns = @ JoinColumn (name = "jobOpenings_id"), inverseJoinColumns = @ JoinColumn (name = "questionSets_id")) @IndexColumn (name & from = "question_sets_idx", basis = 0, nULL = false) public listing lt; QuestionSet & gt; GetQuestionSets () {Return Qtr; }  

QuestionSet:

  @ManyToMany (mappedBy = "questionSets", bringing = FetchType.EAGER) publicly set & lt; JobOpening & gt; GetJobOpenings () {Return Job Openings; } @OneToMany (cascade = CascadeType.ALL, fetch = FetchType.EAGER) @IndexColumn (name = "Prsn_aksks" base = 0) @ the columns (name = "questionet_id", nullable = false) public List & lt; Formquestion & gt; GetQuestions () {return question; }  

FormQuestion:

  @ManyToOne @JoinColumn (name = "questionset_id", insertable = false, updatable = false, null = false) @OnDelete ( Action = On Dealation. CASEADE) Public Question Paper GetQuestionSet () {Return Questions; }  

How can I now ask, amend a question in question set, or change which job is a questionnaire attached? For example, to edit a question in a quiz, I think I should be able to get the question through my ID, change some value, and it has to be merged back, but it does not work is.

I am using Hibernate from the spring (episode), usually as a separate object.

The Hibernate session works slightly differently:

  • < Code> SessionFire creates a session . Often a new session is created for each thread, it is called a session-per-request in web-context.
  • Hibernate three states of objects (entities) - continuously , different and transiently : < / P>

    • Constantly means that the object has been recently loaded from the active session
    • The transient means that the object never has part of the session
    • Separately means that the object once loaded the session, but the session has been closed (and it is not separated from that session)
  • Continuous You do not need to merge, update or do anything - whenever you change your internal position, hibernate already knows that, and it creates the necessary questions on the next flush ()

  • Different objects need to be merged back into sessions, but their identities must be recognizable -

Take a look at

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -