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. sql注入预防

    在我们登陆验证时会发现sql注入的现象. 1.sql注入发生原因 因为如果用户在用户名上输入的是' or 1=1 # 时,我们得到的sql语句是select * from shop_user wher ...

  2. BZOJ 100题纪念

  3. python3 进程_multiprocessing模块

    '''多进程优点:可以利用多核,实现并行运算缺点:1.开销太大: 2.通信困难使用方式跟开多线程一样''' 多进程 import multiprocessing import time,os def ...

  4. date "+Y-%m-%d %H:%M"

     date "+Y-%m-%d %H:%M"    date | awk '{print "Year:"$6  "\t month:"$2  ...

  5. KVM基本概念

    在kvm技术中,应用到的两个东西:qemu和kvm.其中kvm负责cpu虚拟化和内存虚拟化,但是kvm不能模拟其他设备,qemu是模拟IO设备(网卡,磁盘),kvm加上qemu之后就能实现真正意义上的 ...

  6. GCC编译安装

    1. 安装静态库,如果没有安装静态库,后面编译不会通过: yum install glibc-static libstdc++-static -y 2. 下载GCCxxx.tat.gz: wget h ...

  7. ZOJ 3599 K倍动态减法游戏

    下面的文字辅助理解来自http://blog.csdn.net/tbl_123/article/details/24884861 博弈论中的 K倍动态减法游戏,难度较大,参看了好多资料才懵懂! 此题可 ...

  8. python实战===一行代码就能搞定的事情!

    打印9*9乘法表: >>> print( '\n'.join([' '.join(['%s*%s=%-2s' % (y,x,x*y) for y in range(1,x+1)]) ...

  9. 【转】Spring MVC 解读——<mvc:annotation-driven/>

    转载自:http://my.oschina.net/HeliosFly/blog/205343 一.AnnotationDrivenBeanDefinitionParser 通常如果我们希望通过注解的 ...

  10. 一点关于"fat model, skinny controller"的思考

    导言 想来从事服务器端开发也有将近一年的时间,服务端开发不能忽略的一个架构就是MVC架构,但一开始作为小白的我对这些高大上的概念也是很迷惑,由于很长一段时间应对的业务也是十分简单,业务代码也是流水一样 ...