I am new to MyBatis. I was searching for the solution of the following question throughout the day. Still can't find it.
So I have 2 tables in my Database
- instructor
- instructor_detail
Where there is a FK-PK relationship from instructor table to instructor_detail table.
My Instructor.java and InstructorDetail.java is as show below
public class Instructor {
private int id;
private String firstName;
private String lastName;
private String email;
private InstructorDetail instructorDetail;
//constructor,getters and setters
}
public class InstructorDetail {
private int id;
private String youtubeChannel;
private String hobby;
//constructor, getters and setters
}
So I instantiated an Instructor object as follows
InstructorDetail instructorDetail = new InstructorDetail("http://jishnu@youtube.com","Cricket");
Instructor instructor = new Instructor("Jishnu","M V","jishnu@outlook.com");
instructor.setInstructorDetail(instructorDetail);
I want to persist this instructor object in to my database table using MyBatis. How can I do that? If there is a way using XML and/or Annotation. Please help me with both/either of them.