org.hibernate.AnnotationException: Unknown Id.generator: Teacher_GEN

原创 2016年08月31日 10:57:29

hibernate中ID生成策略:

联合主键和Generation_TABLE联合使用,在控制台会报错

八月 31, 2016 10:49:51 上午 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.2.Final}
八月 31, 2016 10:49:51 上午 org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
八月 31, 2016 10:49:51 上午 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
八月 31, 2016 10:49:51 上午 org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity
WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-configuration. Use namespace http://www.hibernate.org/dtd/hibernate-configuration instead.  Support for obsolete DTD/XSD namespaces may be removed at any time.
八月 31, 2016 10:49:52 上午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
八月 31, 2016 10:49:52 上午 org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity
WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-mapping. Use namespace http://www.hibernate.org/dtd/hibernate-mapping instead.  Support for obsolete DTD/XSD namespaces may be removed at any time.
八月 31, 2016 10:49:52 上午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
八月 31, 2016 10:49:52 上午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/hibernate]
八月 31, 2016 10:49:52 上午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=root, password=****}
八月 31, 2016 10:49:52 上午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
八月 31, 2016 10:49:52 上午 org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
八月 31, 2016 10:49:52 上午 org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
<span style="color:#ff0000;">org.hibernate.AnnotationException: Unknown Id.generator: Teacher_GEN</span>
	at org.hibernate.cfg.BinderHelper.makeIdGenerator(BinderHelper.java:641)
	at org.hibernate.cfg.AnnotationBinder.fillComponent(AnnotationBinder.java:2678)
	at org.hibernate.cfg.AnnotationBinder.bindIdClass(AnnotationBinder.java:2742)
	at org.hibernate.cfg.AnnotationBinder.mapAsIdClass(AnnotationBinder.java:997)
	at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:725)
	at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(AnnotationMetadataSourceProcessorImpl.java:245)
	at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(MetadataBuildingProcess.java:222)
	at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:265)
	at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
	at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
	at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:691)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726)
	at com.xh.hibernate.model.TeacherTest.beforeClass(TeacherTest.java:42)
	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:498)
	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.run(ParentRunner.java:363)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	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)

<span style="color:#ff0000;">org.hibernate.AnnotationException: Unknown Id.generator: Teacher_GEN</span>
找不到Id。

所以我们的注解使用Generation_TABLE不可以写在类名称的上面,要写在方法的上面。

@Id
	@javax.persistence.TableGenerator(name = "Teacher_GEN", table = "GENERATOR_TABLE", pkColumnName = "pc_key", valueColumnName = "pc_value", pkColumnValue = "Teacher", allocationSize = 1)
	//表生成器 可以夸平台 很少用
	@SequenceGenerator(name = "teacherSEQ", sequenceName = "teacherSEQ_DB")
	// 使用一个策略 然后sequence名字是teacherSEQ_DB 创建用的是这个名字的表 必须在方法上面,不可以在类上面否则报错
	@GeneratedValue(strategy = GenerationType.TABLE, generator = "Teacher_GEN")
	// 默认使用native 和sequence
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@Id
	@Column(name = "_name")
	// 当前表_不对应的话 自己设定字段名
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

我使用了两种生成Generation_TABLE的方法,可以去掉,只要
 generator = "Teacher_GEN"
和两种Generation_TABLE的其中一个名字相同就可以了,我试了后,都可以正常运行。



oracle错误(五) Unknown Id.generator: sequenceGenerator的解决办法

一、报错信息:
  • zengdeqing2012
  • zengdeqing2012
  • 2016年11月21日 18:31
  • 1600

org.hibernate.AnnotationException: @org.hibernate.annotations.Table references an unknown table:

今天在开发的项目模块中,利用hibernate自动创建表时报org.hibernate.AnnotationException: @org.hibernate.annotations.Table re...
  • xiaxia_jessica
  • xiaxia_jessica
  • 2015年01月29日 18:49
  • 1237

Caused by: org.hibernate.AnnotationException: No identifier specified fo

实体映射oracle数据库表,启动服务时包错误信息:Caused by: org.hibernate.AnnotationException: No identifier specified fo ...
  • yangwenxue_admin
  • yangwenxue_admin
  • 2015年12月17日 13:33
  • 5572

org.hibernate.AnnotationException: mappedBy reference an unknown target entity property

org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: entity.Kpsy...
  • zhangweifeng23
  • zhangweifeng23
  • 2012年12月30日 16:08
  • 3355

org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.demo.pojo.IdCard

TestStudent.testSchemaExport testSchemaExport(com.demo.pojo.dxwj.TestStudent) org.hibernate.Annota...
  • zheng0518
  • zheng0518
  • 2013年09月04日 09:51
  • 3081

NHibernate中自带ID的generator的含义

在日常中我们对数据库中表ID策略的管理,时常模模糊糊的,在什么时候用适当的策略呢?     1、identity:用于MySql数据库。特点:递增            注:对于...
  • Where_the_way
  • Where_the_way
  • 2014年03月11日 17:41
  • 684

nested exception is org.hibernate.AnnotationException: Unknown mappedBy in

nested exception is org.hibernate.AnnotationException: Unknown mappedBy in hibernate逆向工程实体类联系出错...
  • m0_37838381
  • m0_37838381
  • 2017年09月21日 23:13
  • 118

org.hibernate.AnnotationException:(hibernate没有添加配置文件)

org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com...
  • u012115730
  • u012115730
  • 2017年08月10日 15:52
  • 499

hibernate错误org.hibernate.AnnotationException: No identifier specified for entity:

Caused by: org.hibernate.AnnotationException: No identifier specified for entity: com.ffcs.esm.entit...
  • macrobn
  • macrobn
  • 2013年12月04日 14:31
  • 4288

java框架整合错误:org.hibernate.AnnotationException: No identifier specified for entity

在做框架整合的时候,启动的时候就报错:   org.hibernate.AnnotationException: No identifier specified for entity: com.sup...
  • wyc_cs
  • wyc_cs
  • 2012年11月07日 09:13
  • 20613
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:org.hibernate.AnnotationException: Unknown Id.generator: Teacher_GEN
举报原因:
原因补充:

(最多只允许输入30个字)