好久不用hibernat,心里记着的还是hibernate3的标准,今天换成hibernate4.3.8后问题层出不穷啊。。。

首先是hibernate4.3.8中使用mysql方言时,hibernate.cfg.xml中配置的是

<property name="dialect">org.hibernate.dialect.MySQL57InnoDBDialect</property>

其次,在创建SessionFactory时废了不少的功夫,以前的buildSessionFactory()方法过时了,

同时在使用注解时也不能再new AnnotationConfiguration()

查了一番文档后发现建立SessionFactory改用以下代码

 Configuration cfg = new Configuration();
cfg.configure();
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).build();//这里改为build()方法
SessionFactory sf = cfg.buildSessionFactory(serviceRegistry);
Session session = sf.openSession();
session.beginTransaction();
session.save(student);
session.getTransaction().commit();
session.close();
sf.close();

同时,无论是使用xml文件还是注释,现在直接用这套代码都可以创建SessionFactory了,以前的AnnotationConfiguration类

被包含进了Configuration类中!

hibernate4.3.8的dialect和创建SessionFactory遇到的一些问题的更多相关文章

  1. SSH整合创建SessionFactory

    在spring中的 applicationContext.xml中配置如下信息 <!-- 配置数据连接类 --> <bean id="dataSource" cl ...

  2. 实例演示如何在spring4.2.2中集成hibernate5.0.2并创建sessionFactory

    本文地址:http://blog.csdn.net/sushengmiyan/article/details/49388209 文章作者:苏生米沿 本文目的:使用spring4.2.2集成hibern ...

  3. Hibernate初始化创建SessionFactory,Session,关闭SessonFactory,session

    1.hibernate.cfg.xml <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuratio ...

  4. 关于Hibernate 5 和 Hibernate 4 在创建SessionFactory的不同点分析(解决 org.hibernate.MappingException: Unknown entity: xx类报错问题)

    Hibernate4版本的SessionFactory实例构建的步骤是这样的(也是很多学习资料的通用范本): //Configuration就是代表着hibernate的那个xml配置文件对象,如果c ...

  5. Hibernate4和Mysql5.1以上版本创建表出错 type=InnDB

    在搭建springmvc框架时,底层使用hibernate4.1.8,数据库使用mysql5.1,使用hibernate自动生成数据库表 时,hibernate方言使用org.hibernate.di ...

  6. Hibernate创建SessionFactory实例

    private static SessionFactory sessionFactory = null;  static {  Configuration configuration =new Con ...

  7. hibernate配置之<property name="hbm2ddl.auto">create</property>导致每次创建SessionFactory都清空数据库中的数据

    参考:http://stackoverflow.com/questions/6611437/how-to-make-hibernate-not-drop-tables 我遇到的问题就是: List l ...

  8. org.hibernate.InvalidMappingException: Could not parse mapping document from无法创建sessionFactory

    把 "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd" 改为 "http://hibernate.sourc ...

  9. Hibernate3 和Hibernate4 在配置文件上的区别

    在使用hibernate之前要首先对hibernate进行一些基础的配置信息,像映射文件XXX.hbm.xml  XXX代表当前的domain的模型类名 <?xml version=" ...

随机推荐

  1. 36-Ubuntu-用户管理-01-新建用户useradd

    创建用户/设置密码/删除用户/确认用户信息 序号 命令 作用 说明 01 sudo useradd -m -g 组名 新建用户名 添加新用户 -m 自动建立用户家目录 -g 指定用户所在的组,否则会建 ...

  2. 第八篇 编写spider爬取jobbole的所有文章

    通过scrapy的Request和parse,我们能很容易的爬取所有列表页的文章信息. PS:parse.urljoin(response.url,post_url)的方法有个好处,如果post_ur ...

  3. element ui 弹出组件的遮罩层在弹出层的上面的解决方法

    <el-dialog title="收货地址" :visible.sync="dialogFormVisible" :modal-append-to-bo ...

  4. HTML5字体、伪元素、背景

    1.字体样式: 选择器  { font:font-style  font-weight  font-size / line-height   font-family:} 例:p { font: ita ...

  5. 关于windows一些常用的快捷键使用说明

    犹由于经常使用linux和windows,所以有时候就会觉得windows一点需要点击好多下才能够完成的设定非常的麻烦,这里总结一些常用到的快捷键功能,会随着本小白的工作经验而添加. 1.ctrl+a ...

  6. java-----Long转换为 int , string

    int: 1.调用intValue()方法 long ll = 300000; int ii= new Long(ll).intValue(); 2.先把long转换成字符串String,然后在转行成 ...

  7. ul -- li 模拟select下拉框

    在写项目中 用到下拉框,一般用 <select name="" id=""> <option value=</option> &l ...

  8. JUC 一 FutureTask

    java.util.concurrent public class FutureTask<V> implements RunnableFuture<V> 简介 FutureTa ...

  9. Android Studio 安装及汉化

    { https://www.bilibili.com/video/av48649403?from=search&seid=15739157224002905777 Tool: https:// ...

  10. Dart编程运算符

    表达式是一种特殊类型的语句,它计算为一个值.每个表达都由 操作数 - 表示数据 运算符 - 定义如何处理操作数以生成值. 考虑以下表达式 2 + 3.在该表达式中,2和3是操作数,符号+(加号)是 运 ...