1.Eclipse中找不到DB browser
因为不是JAVAEE版本所以需要自己下载DataManagement
解决办法:在Help==>Install New Software;在Work with: 输入Kepler - http://download.eclipse.org/releases/kepler;按回车,稍等片刻,在列表中找到Database Development,勾选,一路 Next 安装后,重启eclipse即可。
2.控制台输出Exception in thread "main" java.lang.NullPointerException
at cn.hrbust.dao.manageUser.main(manageUser.java:37)
显示空指针异常
解决办法:将代码改为如下形式:
package cn.hrbust.dao;
import java.sql.Date;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import cn.hrbust.pojo.User;
public class manageUser {
public static void main(String[] args) {
Configuration cfg =null;
SessionFactory sf=null;
Session session=null;
Transaction ts=null;
User u=new User();
u.setName("马晓雯");
u.setGender("女");
u.setAge(21);
u.setBirthday(Date.valueOf("2000-4-9"));
try {
cfg =new Configuration().configure();
sf=cfg.buildSessionFactory();
session=sf.openSession();
ts=session.beginTransaction();
session.save(u);
ts.commit();
} catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
if(ts !=null) {
ts.rollback();
}
}finally {
session.close();
sf.close();
}
}
}
3.抛出异常Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
解决办法:将jdk版本改为1.8。
4.抛出异常Establishing SSL connection without server‘s identity verification is not recommended
解决办法:在url中添加useSSL=false。
5.抛出异常org.hibernate.exception.GenericJDBCException: could not execute statement
解决办法:改变主键生成方式,将User.hbm.xml文件中的generator class改为assigned,或在建表时将id设置为自增。