如何使用非主键作为引用进行一对一的休眠映射

发布于 2024-12-24 03:18:47 字数 603 浏览 2 评论 0原文

的一对一关系进行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

木槿暧夏七纪年 2024-12-31 03:18:47

如果你没有什么特别的,下面的映射应该可以工作。尽管如此,拥有完整的堆栈跟踪总是有帮助的。

  <many-to-one class="Status" name="statusid" column="StatusId" />

if you dont have something special the following mapping should work. Nevertheless its always helpful to have the full stacktrace.

  <many-to-one class="Status" name="statusid" column="StatusId" />
若有似无的小暗淡 2024-12-31 03:18:47

哦,您真的想加入 User.statusid = Status.statusname 吗?这意味着 statusname 是 Status 的备用键。

在 property-ref 中,您需要设置引用的 Status 对象的属性。
请参阅关联备用键

<many-to-one class="Status" name="statusid" property-ref="statusname"/>

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:

<many-to-one class="Status" name="statusid" property-ref="statusname"/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文