错误 500:无法在 hibernate 映射中初始化集合
我是 Hibernate 的新手。希望你们能帮我调试下面的错误,这真的让我抓狂。
我有一个名为 CONTENT_WORKGROUP 的表,它将映射到另一个名为 CONTENT_WORKGROUP_ROLE 的表。下面是表结构和示例数据:
CONTENT_WORKGROUP
- CM_WORKGROUP_ID NUMBER(15,0)
- WORKGROUP_ID NUMBER(15,0
- ) ROLE_ID VARCHAR2(20 BYTE)
CONTENT_WORKGROUP_ROLE
- CM_WORKGROUP_ROLE_ID NUMBER(
- 15,0) ROLE_ID VARCHAR2(20 BYTE)
- FUNCTION_ID VARCHAR2( 40字节)
P/S:一个用户工作组可以拥有多个角色(创建者、管理员、审批者)。该工作组可以执行的功能(添加、编辑、删除)可以从 CONTENT_WORKGROUP_ROLE 查询。
示例数据:
CONTENT_WORKGROUP
CM_WORKGROUP_ID ; WORKGROUP_ID ROLE_ID
1 第136章 创作者
2 第137章 管理员
3 第136章 管理员
CONTENT_WORK GROUP_ROLE
CM_WORKGROUP_ROLE_ID ; ROLE_ID FUNCTION_ID
1 创建者 &n bsp; ; 复制
2 &n bsp; 编辑
3 &n bsp; 删除
4 &n bsp; 添加
5 nbsp; 编辑
6 nbsp; 批准
7 nbsp; 拒绝
但是,当我获取特定工作组持有的 ContentWorkgroupRole 集合时,我收到错误。
[10/11 15:28:56:053 SGT] 00000039 SystemOut O [2010/11/23 15:28:56.053] 错误 JDBCExceptionReporter - ORA-01722:无效数字
[10/11/23 15:28:56 :100 SGT] 00000039 ServletWrappe E SRVE0068E:在 servlet 的服务方法之一中抛出未捕获的异常:action。抛出异常:javax.servlet.ServletException:无法初始化集合:[corp.celcom.next.infochannel.model.ContentWorkgroup.contentWorkgroupRole#1]
下面是我的休眠映射文件: 内容工作组.hbm.xml
<hibernate-mapping>
<class name="corp.celcom.next.infochannel.model.ContentWorkgroup" table="CM_WORKGROUP" >
<id name="cmWorkgroupId" type="long">
<column name="CM_WORKGROUP_ID" precision="15" scale="0" />
CM_WORKGROUP CM_WORKGROUP_ID
内容工作组角色.hbm.xml
<hibernate-mapping>
<class name="corp.celcom.next.infochannel.model.ContentWorkgroupRole" table="CM_WORKGROUP_ROLE" >
<id name="cmWorkgroupRoleId" type="long">
CM_WORKGROUP_ROLE_ID CM_WORKGROUP_ROLE
<many-to-one name="contentWorkgroup" class="corp.celcom.next.infochannel.model.ContentWorkgroup" fetch="select">
<column name="ROLE_ID" precision="15" scale="0" />
</many-to-one>
在我的 ACTION 类中,这一行发生了上述错误: Iterator iter = cw.getContentWorkgroupRole().iterator();
for(ContentWorkgroup cw : contentWorkgroupList) { Iterator iter = cw.getContentWorkgroupRole().iterator();
while (iter.hasNext()) {
ContentWorkgroupRole role = (ContentWorkgroupRole) iter.next();
if (role.getFunctionId().equalsIgnoreCase(Constant.ADD))
myForm.setAllowAdd(true); if (role.getFunctionId().equalsIgnoreCase(Constant.EDIT)) myForm.setAllowEdit(true); if (role.getFunctionId().equalsIgnoreCase(Constant.DELETE)) myForm.setAllowDelete(true); } 奇怪的是,
当我将 ROLE_ID 更改为 Integer/Long (即 1-Creator,2-Administrator),而不是使用 String 时,它工作得很好!我无法理解我的代码出现问题的原因和问题。
谢谢你的帮助。我已经花了 1 天的时间来处理这个错误。谢谢!
I am a newbie for Hibernate. Hope you guys can help me debug below error which really make me crazy.
I got a table called CONTENT_WORKGROUP which will map to another table called CONTENT_WORKGROUP_ROLE. Below is the table structure and sample data:
CONTENT_WORKGROUP
- CM_WORKGROUP_ID NUMBER(15,0)
- WORKGROUP_ID NUMBER(15,0)
- ROLE_ID VARCHAR2(20 BYTE)
CONTENT_WORKGROUP_ROLE
- CM_WORKGROUP_ROLE_ID NUMBER(15,0)
- ROLE_ID VARCHAR2(20 BYTE)
- FUNCTION_ID VARCHAR2(40 BYTE)
P/S: One user workgroup can have multiple role (Creator, Admin, Approver). The function(Add, Edit, Delete) that can perform by this workgroup can be query from CONTENT_WORKGROUP_ROLE.
Sample DATA:
CONTENT_WORKGROUP
CM_WORKGROUP_ID WORKGROUP_ID ROLE_ID
1 136 Creator
2 137 Administrator
3 136 Administrator
CONTENT_WORKGROUP_ROLE
CM_WORKGROUP_ROLE_ID ROLE_ID FUNCTION_ID
1 Creator Copy
2 Creator Edit
3 Creator Delete
4 Creator Add
5 Administrator Edit
6 Administrator Approve
7 Administrator Reject
However, I am getting the error when I get the SET of ContentWorkgroupRole hold by particular workgroup.
[11/23/10 15:28:56:053 SGT] 00000039 SystemOut O [23/11/2010 15:28:56.053] ERROR JDBCExceptionReporter - ORA-01722: invalid number
[11/23/10 15:28:56:100 SGT] 00000039 ServletWrappe E SRVE0068E: Uncaught exception thrown in one of the service methods of the servlet: action. Exception thrown : javax.servlet.ServletException: could not initialize a collection: [corp.celcom.next.infochannel.model.ContentWorkgroup.contentWorkgroupRole#1]
Below is my hibernate mapping file:
ContentWorkgroup.hbm.xml
<hibernate-mapping>
<class name="corp.celcom.next.infochannel.model.ContentWorkgroup" table="CM_WORKGROUP" >
<id name="cmWorkgroupId" type="long">
<column name="CM_WORKGROUP_ID" precision="15" scale="0" />
CM_WORKGROUP
CM_WORKGROUP_ID
ContentWorkgroupRole.hbm.xml
<hibernate-mapping>
<class name="corp.celcom.next.infochannel.model.ContentWorkgroupRole" table="CM_WORKGROUP_ROLE" >
<id name="cmWorkgroupRoleId" type="long">
CM_WORKGROUP_ROLE_ID
CM_WORKGROUP_ROLE
<many-to-one name="contentWorkgroup" class="corp.celcom.next.infochannel.model.ContentWorkgroup" fetch="select">
<column name="ROLE_ID" precision="15" scale="0" />
</many-to-one>
In my ACTION class, the above mentioned error occured on this line:
Iterator iter = cw.getContentWorkgroupRole().iterator();
for(ContentWorkgroup cw : contentWorkgroupList)
{
Iterator iter = cw.getContentWorkgroupRole().iterator();
while (iter.hasNext()) {
ContentWorkgroupRole role = (ContentWorkgroupRole) iter.next();
if (role.getFunctionId().equalsIgnoreCase(Constant.ADD))
myForm.setAllowAdd(true);
if (role.getFunctionId().equalsIgnoreCase(Constant.EDIT))
myForm.setAllowEdit(true);
if (role.getFunctionId().equalsIgnoreCase(Constant.DELETE))
myForm.setAllowDelete(true);
}
}
The weird part is when I change the ROLE_ID to Integer/Long (i.e 1-Creator, 2-Administrator), instead of using String, it work fine! I couldn't understand why and what the problem on my code.
Thanks for you help. It took me 1 day already to cope with this error. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
抱歉,显示器似乎有点问题。我在这里再写一遍:
ContentWorkgroup.hbm.xml
ContentWorkgroupRole.hbm.xml
在我的 ACTION 类中,这一行发生了上述错误:
迭代器 iter = cw.getContentWorkgroupRole().iterator();
Sorry, the display seem got abit problem. I write again here:
ContentWorkgroup.hbm.xml
ContentWorkgroupRole.hbm.xml
In my ACTION class, the above mentioned error occured on this line:
Iterator iter = cw.getContentWorkgroupRole().iterator();