总结一下Hibernate Helloworld
来源:互联网 发布:钢琴淘宝 编辑:程序博客网 时间:2024/04/30 06:48
很多初学者往往遇到书上讲的Hibernate版本和自己对着书做时所下载的Hibernate版本不一致的问题,有时就产生调试不过,但又是初学,遇到问题很难解决。
一、我已知Hibernate在4.3版本以后,创建SessionFactory的方式应该写成如下方式:
SessionFactory sessionFactory = null;
//1).创建Configuration对象:对应hibernate的基本配置信息和对象映射
Configuration cfg = new Configuration().configure();
//2).4.3创建StandardServiceRegistry
StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings(cfg.getProperties()).build();
//3).创建sessionFactory
sessionFactory = cfg.buildSessionFactory(serviceRegistry);
//2.创建一个Session对象
Session session = sessionFactory.openSession();
以上就是看书后练习可能出现的问题点一。
二、配置数据库方言可能出错
如果你使用的数据库是Mysql V5.1.X以上版本,你应该将数据库方言配置如下,不然,可能出错。
报错1:ids for this class must be manually assigned before--ID不能自动生成,虽然你已经配置了主键为native
报错2:SQLGrammarException: could not execute statementcalling save()--其实就是不能创建表,如果表已存在,则save时,插入没问题。
<property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
以上是问题点二,原因是数据库版本不匹配。
- 总结一下Hibernate Helloworld
- Hibernate 总结(一):HelloWorld
- 简单总结一下Hibernate的缓存问题
- 学习hibernate之后的总结,晒一下
- hibernate helloworld
- Helloworld!Hibernate
- hibernate-helloworld
- Hibernate-HelloWorld
- Hibernate-helloWorld
- Hibernate学习总结(一)——Intellij IDEA下新建Hibernate HelloWorld
- Hibernate HelloWorld-13 hibernate 二级缓存
- 2.1 Hibernate的HelloWorld
- hibernate的helloworld
- Hibernate's HelloWorld
- Hibernate HelloWorld(第一步)
- Hibernate的HelloWorld
- Hibernate HelloWorld(一)
- HelloWorld之Hibernate注解
- Lua垃圾回收
- C++第2次实验二
- Error creating bean with name 'contentTypeAdminController': Injection of autowired dependencies fail
- HDOJ 1287 破译密码(异或运算)
- R语言时间处理
- 总结一下Hibernate Helloworld
- vs2015 卸载
- 数学中几种常用的距离
- 自主学习之RxSwift(一) -----Driver
- 工厂方法模式
- iOS开发中清理沙盒目录的缓存
- 多字文本android:ellipsize属性不正常工作的解决办法
- 结构体,联合和枚举
- Android6.0的处理 转载