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的其中一个名字相同就可以了,我试了后,都可以正常运行。



相关文章推荐

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

今天在开发的项目模块中,利用hibernate自动创建表时报org.hibernate.AnnotationException: @org.hibernate.annotations.Table re...

org.hibernate.MappingException: Unknown entity: com.hibernate.model.Teacher at org.hibernate.impl.S

使用注解Annotation时产生的一下错误: org.hibernate.MappingException: Unknown entity: com.hibernate.model.Teacher...

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

一、报错信息:

org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity:

在做多个表映射,保存数据时报错: org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity: com.h...

(注解方式持久化类报错解决方案-仅供参考)org.hibernate.MappingException: Unknown entity: com.rx.entity.po.User

//实体类 @Entity @Table(name = "T_SECU_USER_INFO") public class User implements Serializable { /** * ...
  • jun_422
  • jun_422
  • 2013年07月16日 15:20
  • 1845

org.hibernate.MappingException: Unknown entity常见问题(新手需注意)

最近学习Hiberante Annotations时遇到了该问题org.hibernate.MappingException: Unknown entity在baidu和googl上搜寻了 很久也没有...

org.hibernate.MappingException: Unknown entity: com.zhou.web.entity.User

1.检查User类,发现注解的配置都没有错//实体User映射到表T_USER @Entity @Table(name="T_USER") public class User { @Id //数...

org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity: botian.entity.User

在新增用户时报错   Messages: Unknown entity: botian.entity.User Unknown entity: botian.entity.User; nest...
  • cai0611
  • cai0611
  • 2012年02月13日 17:57
  • 1021

org.hibernate.MappingException: Unknown entity

====1=== org.hibernate.MappingException: Unknown entity: cjq.hibernate.tutorial.domain.Event  at o...

org.hibernate.MappingException: Unknown entity:

严重: Exception occurred during processing request: Unknown entity: com.hf.gfr.dao.impl.GfTeamPosition...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:org.hibernate.AnnotationException: Unknown Id.generator: Teacher_GEN
举报原因:
原因补充:

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