nested exception is org.hibernate.AnnotationException: Unknown mappedBy in
2017-09-21 23:13
627 查看
使用注解的方式进行hibernate逆向工程出现的Bug
设有表A与表B是一对一的关系(其中外键存在于表B中指向表A)
逆向工程生成的模式是:
表 A(实体类) :
...
@OneToOne(fetch = FetchType.LAZY, mappedBy = "a")
...
表 B(实体类):
....
@OneToOne(fetch = FetchType.LAZY, mappedBy = "b")
....
而实际上mappedBy是使用在OneToOne, OneToMany, ManyToMany中没有外键的一方
而存在外键的一方应该使用
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "a")
so正确应该是 :
表A:
...
@OneToOne(fetch = FetchType.LAZY, mappedBy = "a")
...
表B:
...
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "b_a")
...
结论 : 逆向工程也可能出错
设有表A与表B是一对一的关系(其中外键存在于表B中指向表A)
逆向工程生成的模式是:
表 A(实体类) :
...
@OneToOne(fetch = FetchType.LAZY, mappedBy = "a")
...
表 B(实体类):
....
@OneToOne(fetch = FetchType.LAZY, mappedBy = "b")
....
而实际上mappedBy是使用在OneToOne, OneToMany, ManyToMany中没有外键的一方
而存在外键的一方应该使用
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "a")
so正确应该是 :
表A:
...
@OneToOne(fetch = FetchType.LAZY, mappedBy = "a")
...
表B:
...
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "b_a")
...
结论 : 逆向工程也可能出错
相关文章推荐
- org.hibernate.AnnotationException: mappedBy reference an unknown target entity property
- nested exception is org.hibernate.MappingException: Unknown entity,问题解决
- apfuse2.0.2 nested exception is org.hibernate.hql.ast.QuerySyntaxException: Otacity is not mapped
- Unknown integral data type for ids : java.lang.String; nested exception is org.hibernate.id.Identifi
- nested exception is org.hibernate.PropertyNotFoundException: Could not find a getter for eNum in class
- is not mapped.nested exception is org.hibernate.hql.ast.QuerySyntaxException: user_kissfly
- org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (The database is already in use by another p
- Unknown integral data type for ids : java.lang.String; nested exception is org.hibernate.id.Identifi
- Error while indexing in Hibernate Search(before transaction completion); nested exception is org.hib
- nested exception is org.hibernate.AnnotationException: No identifier specified for entity
- nested exception is org.hibernate.hql.ast.QuerySyntaxException: users is not mapped. [from users]
- org.hibernate.AnnotationException: Associations marked as mappedBy must not define database mappings
- nested exception is org.hibernate.hql.ast.QuerySyntaxException: Product is not mapped [from Product]
- 2.Unknown entity: java.util.ArrayList; nested exception is org.hibernate.MappingException: Unknown e
- Caused by: org.hibernate.hql.ast.QuerySyntaxException: TkltEmpQuitProcess is not mapped. 问题解决
- Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [from User
- 使用hibernate的hql语句做查询报错 org.hibernate.hql.internal.ast.QuerySyntaxException: user is not mapped
- org.hibernate.hql.ast.QuerySyntaxException: Category is not mapped [from Category]
- HTTP Status 500 - could not execute query; nested exception is org.hibernate.exception.JDBCConnectio
- org.hibernate.hql.internal.ast.QuerySyntaxException: ### is not mapped