為什么視頻中事務不用調用begin()方法直接提交就可以運行,我的卻提示事務沒有成功打開?我百度了下,事務提交之前先調用事務的begin()方法就完美運行了?
2016-08-04
在 class Grade 中,
Set<Student> students;//為初始化
//改為
Set<Student> students =new HashSet<Student>();
這樣 g.getStudents() 已初始化。
Set<Student> students;//為初始化
//改為
Set<Student> students =new HashSet<Student>();
這樣 g.getStudents() 已初始化。
2016-08-04
本節出現的問題:1.使用grade.getStudents().add(stu1);拋出異常。辦法:使用前調setStudetns事例化集合:grade.setStudents( new HashSet<Student>());2.在findStudentsByGrade()方法中出現空指針異常,檢查后發現是查詢grade返回的是null。解決辦法:將hibernate.cfg.xml中的<property name="hbm2ddl.auto">create</property>的create修改為update 要不然每次數據庫操作都會創建新表會覆蓋你原來的表,導致已插入的數據丟失。
2016-07-26
最新回答 / 錫雋
感覺報空指針的情況很多 , 我遇到的 mapping里沒寫package屬性會報空指針 , Set后面沒有寫new HashSet也會報空指針 。。? 好尷尬
2016-07-26
在findStudentsByGrade()方法中出現空指針異常,在Grade的構造方法里,初始化學生類
public Grade(String gname, String gdesc) {
super();
this.students = new HashSet<Student>();
this.gname = gname;
this.gdesc = gdesc;
}
public Grade(String gname, String gdesc) {
super();
this.students = new HashSet<Student>();
this.gname = gname;
this.gdesc = gdesc;
}
2016-07-25
初始化一下
Grade g=new Grade("Java二班", "Java軟件開發二班");
g.setStudents(new HashSet<Student>());
Grade g=new Grade("Java二班", "Java軟件開發二班");
g.setStudents(new HashSet<Student>());
2016-07-23
inverse="true" 把維護的權限給了多的一方,1的一方根本就不維護了,怎么可能去更新多的一方的表,也是醉了
2016-07-22