我收到以下Hibernate异常:
org.hibernate.AnnotationException: @OneToOne or @ManyToOne on cz.rohan.dusps.model.Switchport.konfiguracniTemplateAccess references an unknown entity: cz.rohan.dusps.model.KonfiguracniTemplate
org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:103)
org.hibernate.cfg.AnnotationConfiguration.processEndOfQueue(AnnotationConfiguration.java:541)
org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:523)
org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:380)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1377)
org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954)
cz.rohan.dusps.helper.SessionFactoryHelper.initFactory(SessionFactoryHelper.java:122)
cz.rohan.dusps.helper.SessionFactoryHelper.getSessionFactory(SessionFactoryHelper.java:134)
cz.rohan.dusps.filter.HistorieZmenFilter.doFilter(HistorieZmenFilter.java:102)
cz.rohan.dusps.filter.CharsetFilter.doFilter(CharsetFilter.java:41)
Run Code Online (Sandbox Code Playgroud)
在与各种人一起度过了大约20个小时的问题后,阅读了所有可能的博客或论坛,我真的在这里绝望了.
这是一个中型项目.我应该提到数据库是Postgres 9.1,我们使用建模工具生成数据库.Hibernate连接到数据库但不生成它.
我在数据库中创建了一个新实体,它叫做"KonfiguracniTemplate"(配置模板).我已经创建了模型,控制器,表单,验证器,.jsp,它们基本上都是从类似性质的现有实体中以1:1复制的.我现在可以使用KonfiguracniTemplate,CRUD完全正常工作.
当我从名为Switchport的实体引用此KonfiguracniTemplate时出现问题.在DB中,两者之间存在关系:
在.../model/Switchport.java中,关系的映射就像所有其他正常工作的关系一样:
@ManyToOne
@JoinColumn(nullable = false)
private KonfiguracniTemplate konfiguracniTemplateAccess;
Run Code Online (Sandbox Code Playgroud)
我尝试了各种形式:
@ManyToOne
@JoinColumn(name="konfiguracnitemplateaccess_id", nullable = false)
private KonfiguracniTemplate konfiguracniTemplateAccess;
Run Code Online (Sandbox Code Playgroud)
要么
@ManyToOne(targetEntity=KonfiguracniTemplate.class)
@JoinColumn(name="konfiguracnitemplateaccess_id", nullable = false)
private KonfiguracniTemplate konfiguracniTemplateAccess;
Run Code Online (Sandbox Code Playgroud)
我也检查过:
无论我尝试什么,我都无法摆脱"引用未知实体"的例外.有人可以分享一个想法,或者可能如何调试问题?帖子顶部的堆栈跟踪是我在日志中得到的全部内容.
所有输入都非常感谢!