-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: What's wrong with my design of mapping to database?
PostPosted: Thu Jul 14, 2016 9:43 am 
Newbie

Joined: Wed Jul 13, 2016 10:40 pm
Posts: 17
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.java
Code:
@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.java
Code:
@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.java
Code:
@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.java
Code:
@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.java
Code:
@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;


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.