如何使用非主键作为引用进行一对一的休眠映射
的一对一关系进行 XML Hibernate 映射
我正在尝试为表User (UserId、Name、StatusId) 状态(StatusId,StatusName)
我尝试了在论坛上
在User.hbm.xml下
<many-to-one class="Status" name="statusid" property-ref="statusid">
<column name="statusname" />
</many-to-one>
找到的这个,因为我得到了这个错误
严重:初始SessionFactory创建失败.java.lang.NullPointerException 警告:StandardWrapperValve[默认]:PWC1406:Servlet 默认的 Servlet.service() 引发异常 java.lang.ExceptionInInitializerError
当我使用 PK 作为参考时,我没有收到此错误..
任何人都可以解释一下该属性的含义是什么以及为什么我会收到此错误? PS:我正处于学习阶段,请大家帮忙>.<
I'm trying to do a XML Hibernate mapping for a one to one relation for tables
User ( UserId, Name, StatusId)
Status (StatusId, StatusName)
i tried this that i found on the forum
Under User.hbm.xml
<many-to-one class="Status" name="statusid" property-ref="statusid">
<column name="statusname" />
</many-to-one>
and becoz of this i got this error
SEVERE: Initial SessionFactory creation failed.java.lang.NullPointerException
WARNING: StandardWrapperValve[default]: PWC1406: Servlet.service() for servlet default threw exception
java.lang.ExceptionInInitializerError
When I use the PK as the reference, i don't receive this error ..
Can anybody please explain what does the property means and why am i getting this error?
PS: I'm in a learning stage, please help >.<
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果你没有什么特别的,下面的映射应该可以工作。尽管如此,拥有完整的堆栈跟踪总是有帮助的。
if you dont have something special the following mapping should work. Nevertheless its always helpful to have the full stacktrace.
哦,您真的想加入
User.statusid = Status.statusname
吗?这意味着 statusname 是 Status 的备用键。在 property-ref 中,您需要设置引用的 Status 对象的属性。
请参阅关联备用键:
Oh, you really want to join on
User.statusid = Status.statusname
? This means that statusname is an alternate key for Status.In your property-ref you need to set the property of the Status object that you refer to.
See Associations on Alternate Keys: