在进行学习具体类单表继承时使用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>