初识Hibernate:Could not instantiate id generator [entity-name=com.hibernate.e
来源:互联网 发布:html img 调用js方法 编辑:程序博客网 时间:2024/06/06 00:41
最近刚刚学 Hibernate 然后就遇到了错误,抓破了脑壳都不知道为什么,第二天又看了一遍代码,原来是我写错了单词
<id name="deptNo" type="java.lang.Byte">
<column name="deptno"/>
<generator class="assigned"/> //这个地方要注意,别写错
</id>
org.hibernate.MappingException: Could not instantiate id generator [entity-name=com.xxx.xxx.xxx.Dept] at org.hibernate.id.factory.DefaultIdentifierGeneratorFactory.createIdentifierGenerator(DefaultIdentifierGeneratorFactory.java:118) at org.hi
源代码如下:
hibernate.cfg.xml-------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"><hibernate-mapping>e.entity.Dept" table="dept" schema<class name="com.xxx.hibernat="SCOTT"><id name="deptNo" type="java.lang.Byte"><column name="deptno"/><!-- 主键生成策略:increment:自动增<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-configuration PUBLIC"-//Hibernate/Hibernate Configuration DTD 3.0//EN""http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"><hibernate-configuration><session-factory><!-- 1 数据库的连接字符串 --><property name="connection.url">jdbc:oracle:thin:@127.0.0.1:1521:orcl</property><!-- 2 登陆数据库的用户名 --><property name="connection.username">scott</property><!-- 3 登陆数据库的密码 --><property name="connection.password">scott</property><!-- 4 连接数据库的驱动类 --><property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property><!-- 5 数据库方言 --><property name="dialect">org.hibernate.dialect.OracleDialect</property><!-- 6 运行的时候显示sql语句--><property name="show_sql">true</property><!-- 7 格式化sql语句--><property name="format_sql">true</property><!-- 8 和当前线程绑定在一起 --><property name="current_session_context_class">thread</property><!-- 注册映射文件 --><!-- /hiberate-chap1/src/com/xxx/hibernate/entity/Dept.hbm.xml --><mapping resource="com/xxx/hibernate/entity/Dept.hbm.xml"/></session-factory></hibernate-configuration>
长;assigned:程序提供;native:由程序自己判断是程序提供主键值还是由数据库生成主键identity:使用数据的自动增长;
如mysql的auto_increment,sqlserver的identity(标识列)sequence:使用序列;如Oracle,比如Oracle数据库有有一个名为:seq_dept的序列,
那么在此处配置为:<generator class="sequence"><param name="sequence">seq_dept</param></generator> --><generator class="assigned"/></id>
<!-- property元素中的name属性值是实体类中的属性名称,type的属性值指的是实体类中对应属性的数据类型,column的属性值指的是数据库中表对应的列名 -->
<property name="deptName" type="java.lang.String" column="dname"/>
<property name="location" type="java.lang.String"><column name="loc"/>
</property></class></hibernate-mapping>
Dept.hbm.xml-------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"><hibernate-mapping><class name="com.XXX.hibernate.entity.Dept" table="dept" schema="SCOTT"><id name="deptNo" type="java.lang.Byte"><column name="deptno"/><!-- 主键生成策略:increment:自动增长;assigned:程序提供;native:由程序自己判断是程序提供主键值还是由数据库生成主键identity:使用数据的自动增长;如mysql的auto_increment,sqlserver的identity(标识列)sequence:使用序列;如Oracle,比如Oracle数据库有有一个名为:seq_dept的序列,那么在此处配置为:<generator class="sequence"><param name="sequence">seq_dept</param></generator> --><generator class="assigned"/></id><!-- property元素中的name属性值是实体类中的属性名称,type的属性值指的是实体类中对应属性的数据类型,column的属性值指的是数据库中表对应的列名 --><property name="deptName" type="java.lang.String" column="dname"/><property name="location" type="java.lang.String"><column name="loc"/></property></class></hibernate-mapping>原创作品:转摘请注明出处
阅读全文
0 0
- 初识Hibernate:Could not instantiate id generator [entity-name=com.hibernate.e
- hibernate-------could not instantiate id generator
- org.hibernate.MappingException: could not instantiate id generator
- org.hibernate.MappingException: could not instantiate id generator
- could not instantiate id generator
- org.hibernate.HibernateException: Could not instantiate resultclass: com.bocean.entity.vo.HospitalVo
- 在Hibernate中配置Hilo进行数据绑定测试时出错:org.hibernate.MappingException: Could not instantiate id generator
- org.hibernate.HibernateException: could not instantiate RegionFactory
- Stacktraces org.hibernate.QueryException: could not resolve property: name of: Entity.Person [ from
- org.hibernate.exception.GenericJDBCException: could not insert: [com.qdd.entity.Book] 的解决方法
- hibernate 实体类注解错误:Could not determine type for: com.xxx.entity.Site
- HTTP Status 500 - Hibernate operation: could not insert: [com.qm.entity.Img]; uncategorized SQLExcep
- hibernate -----Could not instantiate cache implementation异常处理
- hibernate -----Could not instantiate cache implementation异常处理
- could not instantiate RegionFactory [org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridg
- Could not instantiate bean class [org.hibernate.cfg.Configuration]: Construct
- could not instantiate RegionFactory [org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridg
- could not instantiate RegionFactory [org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBrid
- 【R 可视化】R 画关系网络图
- 【Python】10“生成器和迭代器“
- 图像拼接算法总结(一)
- 100以内加减法
- Oracle锁表查询和解锁方法
- 初识Hibernate:Could not instantiate id generator [entity-name=com.hibernate.e
- 【spark 数据框】Spark数据框dataFrame
- 怎么进入 BAT 的研发部门?
- 要不要跳槽?你不该接受公司挽留的九个原因
- 领域驱动设计系列文章(2)——浅析VO、DTO、DO、PO的概念、区别和用处
- git fetch, git pull, git pull -rebase区别
- 创建 工程和myworkspace工作空间、静态库和框架之间的关系
- mongodb修改字段名称
- centos6.5 oracle安装