0

Those are my classes:

@Entity
@Table(name="assessment")
public class AssesmentProperties {

  @Id
  @Column(name="AssessmentId")
  @GeneratedValue(strategy=GenerationType.IDENTITY)
  private Long AssessmentId;

  @Column(unique=true,nullable=false)
  private String AssessmentName;

  private String AssessmentLevel;
  private String  Specialization;
  private int time;
  private String keywords;
  private int NoOfSections;

  //getters and setters
}


@Embeddable
public class SettingsPrimary implements Serializable {

  private Long AssessmentId;

  @GeneratedValue(strategy=GenerationType.IDENTITY)
  private Long Section;

 //getters and setters
}


@Entity
@Table(name="section")
public class SectionProperties {

  @EmbeddedId
  private SettingsPrimary PrimaryKey;

  private String SectionType;
  private int Weightage;
  private int time;
  private int NoOfQuestions;

  //getters and setters
}

In the table section I need to create assessment_id as FK to assessment table and set cascade on delete. I have tried to do it with different ways but without success.

1
  • 1
    Create an attribute of type AssesmentProperties? You can set the cascade in the @OneToOne or @ManyToOne annotation using cascade= Commented Sep 6, 2020 at 7:03

1 Answer 1

1

Maybe this could help you.

@Entity
@Table(name="section")
public class SectionProperties {

  @Id
  private Long PrimaryKey;

  @ManyToOne(cascade = CascadeType.ALL)
  @JoinColumn(name = "assessment_id", referencedColumnName="AssessmentId")
  private AssesmentProperties AssesmentProperties;

  private String SectionType;
  private int Weightage;
  private int time;
  private int NoOfQuestions;

  //getters and setters
}

I changed the SectionProperties id to a Long and mapped the AssessmentProprties into a ManytoOne prop. This way, always that a AssessmentProperties binded to a Section will be deleted, the associated SectionProperties will too.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.