在Hibernate中配置Hilo进行数据绑定测试时出错:org.hibernate.MappingException: Could not instantiate id generator
在进行学习具体类单表继承时使用hilo类型时总是在调度过程中提示如下信息,无法通过。留下记录备查。
在网上找相关信息,
未解决,详细如下:
org.hibernate.MappingException: Could not instantiate id generator [entity-name=cn.opfo.app.domain.Person]
at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.createIdentifierGenerator(DefaultIdentifierGeneratorFactory.java:121)
at org.hibernate.mapping.SimpleValue.createIdentifierGenerator(SimpleValue.java:265)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:287)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
at cn.opfo.app.test.HibernateJUnitTest.setUp(HibernateJUnitTest.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.UnsupportedOperationException: Support for 'hilo' generator has been removed
at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.getIdentifierGeneratorClass(DefaultIdentifierGeneratorFactory.java:132)
at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.createIdentifierGenerator(DefaultIdentifierGeneratorFactory.java:112)
... 30 more
java.lang.NullPointerException
at cn.opfo.app.test.HibernateJUnitTest.tearDown(HibernateJUnitTest.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2016-1-24 23:31:37 by Hibernate Tools 3.5.0.Final -->
<!-- hibernate-mapping的相关属性 name 指定需要持久化类(包——类名) table 指定需要映射的表名 default-lazy="true"
延迟加载默认true dynamic-insert="true" 没有赋值的属性不会参与新增操作(对持久化状态的有效) dynamic-update="true"
没有赋值的属性不会参与更新操作(对持久化状态的有效) mutable=false 表示不允许更新,可以新增与删除。如性别 select-before-update=true
执行更新之前先发起一条SQL查询,确认数据是否与表不一致,如果不致更新,一致则不更新 where="" 在查询之前附带一个查询条件(where name="cust")
formula 通过在属性中设定子查询返回相关数据,在实体类中设定相应参数获取其返回值并做相应后处理。 -->
<!-- Property部分的属性设定 name="propertyName" 属性名 column="column_name" 列名 type="typename"
类型名 length=10 字段长度 precision 指定数值的有效位数 scale 指定小数的位数 not-null="true|false"
是否允许为空 update="true|false" 表明在用于Update时是否包括此字段 insert="true|false" 表明在用于Insert时是否包括此字段
unique="true|false" 唯一约束 unique-key="true|false" 唯一约束名称 lazy="true|false"
指定是否延迟加载 index="true|false" 用于为该列建索引 -->
<!-- 缓存:一级缓存、二级缓存、查询缓存三种 一级缓存:Session缓存,都是持续化缓存与数据库相对应。需要时可直接从缓存中把持而无需再到数据库中获取。
二级缓存: -->
<!-- 数据类型映射由Hibernate自动完成,详细参照相关资料。 支持自定义:UserType\CompositeUserType -->
<hibernate-mapping default-lazy="false" package="cn.opfo.app.domain">
<!-- 如果辨别列使用的是int或char类型必须要手动的给每个类指定一个辨别值 discriminator-value="1"指定辨别值 -->
<class name="Person" table="PERSON" dynamic-update="true">
<id name="id">
<column name="ID" />
<generator class="hilo">
<param name="table">high_val</param>
<param name="column">next_val</param>
<param name="max_lo">5</param>
</generator>
</id>
<property name="name">
<column name="NAME" />
在JUnit下测试总是提示错误。
package cn.opfo.app.test;
import java.util.Date;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import cn.opfo.app.domain.Person;
import cn.opfo.app.domain.Student;
public class HibernateJUnitTest {
private SessionFactory sFactory;
Session session;
Transaction tx;
/*
* 测试
前进行初始化
*/
@Before
public void setUp() throws Exception {
System.out.println("-----初始化数据------");
Configuration config = new Configuration().configure();
// ServiceRegistry sr = new
// StandardServiceRegistryBuilder().applySettings(config.getProperties()).build();
// sFactory = config.buildSessionFactory(sr);
sFactory = config.buildSessionFactory();
session = sFactory.openSession();
}
/*
* 测试之后释放数据
*/
@After
public void tearDown() throws Exception {
System.out.println("-----释放化数据------");
if (session.isOpen()) {
session.close();
}
}
/*
* 测试代码
*/
@Test
public void testSubClass2() {
Student s = new Student("王立夫", 1343, new Date(), 15, 98.5F);
tx = session.beginTransaction();
session.persist(s);
tx.commit();
}
</property>
<property name="passowrd">
<column name="PASSOWRD" />
</property>
<property name="birthDay">
<column name="BIRTHDAY" />
</property>
<!-- 通过union-subclass配置子类 -->
<union-subclass name="Student" table="t_student">
<property name="number" />
<property name="score" />
</union-subclass>
</class>
</hibernate-mapping>
在Hibernate中配置Hilo进行数据绑定测试时出错:org.hibernate.MappingException: Could not instantiate id generator的更多相关文章
- Spring Boot启动 Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not instantiate id generator错误
开始运行得很好的项目,因为前一天高度了项目结构和名称突然报上面的错误 查了很多网上资料很多解决方案 造成这个错误的原因有很多,例如 1.@Entity 类有变动,无非正常生成对应的数据库. 解决:使用 ...
- visual 2008中error PRJ0003 : 生成 cmd.exe 时出错
visual 2008中error PRJ0003 : 生成 cmd.exe 时出错”, 和vs2008 sp1没关系 解决方案:工具—>选项—>项目和解决方案—>VC++目录, ...
- Hibernate 中配置属性详解(hibernate.properties)
Hibernate能在各种不同环境下工作而设计的, 因此存在着大量的配置参数.多数配置参数都 有比较直观的默认值, 并有随 Hibernate一同分发的配置样例hibernate.properties ...
- 详解在Hibernate中配置数据库方言的作用和好处以及各种数据库的方言连接
Hibernate底层依然使用SQL语句来执行数据库操作,虽然所有关系型数据库都支持使用标准SQL语句,但所有数据库都对标准SQL进行了一些扩展,所以在语法细节上存在一些差异,因此Hibernate需 ...
- linux 中配置假域名来测试
1.linux中配置假域名 找到hosts文件进行编辑 命令:vim /etc/hosts 配置: #centos(本机IP)192.168.1.179 www.imooc.com(假域名,自己设置) ...
- 安装SQL Server 2012过程中出现“启用windows功能NetFx3时出错”(错误原因、详细分析及解决方法)以及在Windows Server2012上安装.NET Framework 3.5的详细分析及安装过程
问题:在服务器(操作系统为Windows server 2012)上安装SQL Server 2012的过程中,安装停留在下图所示的界面上,显示”正在启用操作系统功能NetFx3”随后出 ...
- hibernate中配置单向多对一关联,和双向一对多,双向多对多
什么是一对多,多对一? 一对多,比如你去找一个父亲的所有孩子,孩子可能有两个,三个甚至四个孩子. 这就是一对多 父亲是1 孩子是多 多对一,比如你到了两个孩子,它们都是有一个共同的父亲. 此时孩子就是 ...
- VS 中NuGet 尝试还原程序包时出错"*"已拥有为"**"定义的依赖项
之前从Git检出项目以后,项目编译不能通过,发现是缺少依赖的外部插件,于是通过NuGet去获取项目依赖的插件,如何通过NuGet恢复使用的插件请使用NuGet还原项目插件. 但是就是在使用NuGet还 ...
- Python中使用json.loads解码字符串时出错:ValueError: Expecting property name: line 1 column 1 (char 1)
解决办法,json数据只能用双引号,而不能用单引号
随机推荐
- HTML5新增元素、标签总结
总是遇到h5新标签的笔试题目,就查阅了资料来总结一下: 1.form相关: (1)form属性:在HTML5中表单元素可放在表单之外,通过给该元素添加form属性来指向目标表单(form属性值设为目标 ...
- jenkins插件开发-此路是我开
一:前置环境 1. JDK1.6+ 2. maven已安装 3. jenkins已搭建 4. eclipse已安装(并安装了maven插件) 以上环境可以百度搜索并安装 我的环境是WIN7 64位系统 ...
- 制作圆角:《CSS3 Border-radius》
今天我们在一起来看看CSS3中制作圆角的属性border-radius的具体用法.如今CSS3中的border-radius出现后,让我们没有那么多的烦恼了,首先制作圆角图片的时间是省了,而且其还有多 ...
- 阻抗计算公式、polar si9000(教程)
给初学者的一直有很多人问我阻抗怎么计算的. 人家问多了,我想给大家整理个材料,于己于人都是个方便.如果大家还有什么问题或者文档有什么错误,欢迎讨论与指教!在计算阻抗之前,我想很有必要理解这儿阻抗的意义 ...
- 2.4G高频PCB天线设计
2.4G高频PCB天线设计 本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明. 参考链接: http://bbs.rfeda.cn/read-htm-t ...
- PHP匿名函数的使用
$dealer = array(); array_walk($dealer_id_arr,function($value) use(&$dealer) { $dealer[] = get_co ...
- iOS开发数据库篇—SQLite常用的函数
iOS开发数据库篇—SQLite常用的函数 一.简单说明 1.打开数据库 int sqlite3_open( const char *filename, // 数据库的文件路径 sqlite3 * ...
- IE6兼容性问题及IE6常见bug详细汇总
转载地址:http://www.jb51.net/css/76894.html 1.IE6怪异解析之padding与border算入宽高 原因:未加文档声明造成非盒模型解析 解决方法:加入文档声明&l ...
- iPhone6搜索如何打开?详细使用方法
iphone6搜索功能在哪?怎么用呢?当iPhone6中安装了太多的应用或者联系人太多时,我们就可以使用iPhone6搜索功能就能快速找到,但是还有很多朋友对于iphone6搜索功能在哪,怎么用还不太 ...
- MFC编程入门之十二(对话框:非模态对话框的创建及显示)
上一节讲了模态对话框及其弹出过程,本节接着讲另一种对话框--非模态对话框的创建及显示. 非模态对话框显示后,程序其他窗口仍然能正常运行,可以响应用户输入,还可以相互切换.上一讲中创建的Tip模态对话框 ...