I get a null session (NullPointerException) and through debug I find my sessionFactory is null. When I remove my mapping class configure, the sesionFactory is not null, so I think there are some mistakes in my design of mapping.
The annotation part of the codes showing my design of mapping to a database are as follows.
Project.javaCode:
@Entity
@Table(name = "project_info")
public class Project {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer project_id;
private ProjectBasicInfo project_basic_info;
@ElementCollection(targetClass = String.class)
@CollectionTable(name = "project_extra_info", joinColumns = @JoinColumn(name = "project_id", nullable = false))
@Column(name="extra_info_name")
private List<String> project_extra_info = new LinkedList<String>();
@ManyToMany(targetEntity=Student.class)
@JoinTable(name="project22student",
joinColumns=@JoinColumn(name="project_id"
, referencedColumnName="project_id"),
inverseJoinColumns=@JoinColumn(name="student_id"
, referencedColumnName="student_id")
)
private Set<Student> stundet
= new HashSet<Student>();
ProjectBasicInfo.javaCode:
@Embeddable
public class ProjectBasicInfo {
@Column(name="project_name", nullable=false)
private String project_name;
@Column(name="project_manager", nullable=false)
private String project_manager;
@Column(name="hoster")
private String hoster;
@Parent
private Project owner;
}
Student.javaCode:
@Entity
@Table(name = "student_info")
public class Student {
@Id
@Column(name="student_id")
private String student_id;
private StudentBasicInfo student_basic_info;
@ElementCollection(targetClass=String.class)
@CollectionTable(name="student_project_info", joinColumns = @JoinColumn(name="student_id", nullable = false))
@Column(name="extra_info_value", nullable=false)
@MapKeyClass(StudentProjectInfoKey.class)
private Map<StudentProjectInfoKey, String> studentProjectInfo = new HashMap<StudentProjectInfoKey, String>();
@ManyToMany(targetEntity=Project.class)
@JoinTable(name="project22student",
joinColumns=@JoinColumn(name="student_id"
, referencedColumnName="student_id"),
inverseJoinColumns=@JoinColumn(name="project_id"
, referencedColumnName="project_id")
)
private Set<Project> project
= new HashSet<Project>();
StudentBasicInfo.javaCode:
@Embeddable
public class StudentBasicInfo {
@Column(name="name")
private String name;
@Column(name="id")
private String id;
@Column(name="clazz")
private String clazz;
@Column(name="major")
private String major;
@Column(name="academy")
private String academy;
@Column(name="grade")
private String grade;
@Parent
private Student owner;
StudentProjectInfoKey.javaCode:
@Embeddable
public class StudentProjectInfoKey {
@Column(name="project_id")
private Integer project_id;
@Column(name="project_extra_info_name")
private String project_extra_info_name;
@Parent
private Student owner;