1. 入门http://jingyan.baidu.com/article/cbf0e500965a352eab289368.html
  2. 步骤
    1、查看是否hibernate支持:file-->plugins-->hibernate(搜索)
    2、新增web project,勾选web application、hibernate、create default hibernate
    3、点击左下角框框,弹出database,读取sqlserver数据库数据自动生成配置文件
    4、编写测试程序实现插入数据操作
    public class HTest {
    public static void main(String[] args) {
    TableName log = new TableName();
    // log.setId(10001);
    log.setAid(1);
    log.setRelatedId("111"); try {
    String remark="111的备注";
    String ret = new String(remark.getBytes("ISO-8859-1"),"GB2312");
    log.setRemark(ret);
    } catch (UnsupportedEncodingException e) {
    e.printStackTrace();
    } DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date date = new Date();
    String dateStr = sdf.format(date);
    log.setCreated(Timestamp.valueOf(dateStr)); SessionFactory fac= new AnnotationConfiguration().configure().buildSessionFactory(); // Configuration configuration = new Configuration();
    // SessionFactory fac = configuration.configure().buildSessionFactory(); Session session =fac.getCurrentSession();
    session.beginTransaction();
    session.save(log);
    session.getTransaction().commit();
    }
  3. 过程中遇到的问题及解决方案
      1、 Could not load requested class : com.microsoft.sqlserver.jdbc.SQLServerDriver
   解决方法:缺少sqlserver驱动导致
    1、下载sqljdbc4.jar 
    2、file-->project structure-->modules-->dependencies-->引入sqljdbc4.jar
 
   2、No CurrentSessionContext configured 
          解决方法:hibernate.cfg.xml配置文件中加上节点:<property name="current_session_context_class">thread</property>
 
    3、当 IDENTITY_INSERT 设置为 OFF 时,不能为表 '' 中的标识列插入显式值
  解决方法:sqlserver中主键为自增长导致,数据库对应的实体类加上:
  @GeneratedValue(strategy = GenerationType.IDENTITY)
 
   4、hibernate写入数据库时出现乱码
          解决方法:暂未找到解决方法

java_hibernate的更多相关文章

随机推荐

  1. Spring发展史

    https://www.cnblogs.com/RunForLove/p/4641672.html

  2. 程序异常退出 却没有产生core文件

    程序异常退出  却没有产生core文件 http://www.cnblogs.com/my_life/articles/4107333.html

  3. Ubuntu部署Java web项目

    登录服务器和给服务器传输文件,使用的工具是Xshell Xftp Mysql 安装mysql 输入:sudo apt-get update                     更新软件列表 输入: ...

  4. ajax邮箱、用户名唯一性验证

    <script type="text/javascript"> $(function () { $("#txtEmail").blur(functi ...

  5. Oracle查看被锁的表,并释放

    几个相关的表 SELECT * FROM v$lock; SELECT * FROM v$sqlarea; SELECT * FROM v$session; SELECT * FROM v$proce ...

  6. 关系和非关系型数据库区别(以及oracle和mysql的区别)

    一.关系型数据库 关系型数据库,是指采用了关系模型来组织数据的数据库.    关系模型是在1970年由IBM的研究员E.F.Codd博士首先提出的,在之后的几十年中,关系模型的概念得到了充分的发展并逐 ...

  7. Rescue The Princess

    Description Several days ago, a beast caught a beautiful princess and the princess was put in prison ...

  8. CF A.Mishka and Contest【双指针/模拟】

    [链接]:CF/4892 [题意]: 一个人解决n个问题,这个问题的值比k小, 每次只能解决最左边的或者最右边的问题 解决了就消失了.问这个人能解决多少个问题. [代码]: #include<b ...

  9. ZOJ 2112 Dynamic Rankings (动态第 K 大)(树状数组套主席树)

    Dynamic Rankings Time Limit: 10 Seconds      Memory Limit: 32768 KB The Company Dynamic Rankings has ...

  10. UVA 699 The Falling Leaves (递归先序建立二叉树)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/19244 #include <iostream> #include <cstdio> # ...