错误 500:无法在 hibernate 映射中初始化集合

发布于 2024-10-04 02:33:10 字数 5229 浏览 8 评论 0原文

我是 Hibernate 的新手。希望你们能帮我调试下面的错误,这真的让我抓狂。

我有一个名为 CONTENT_WORKGROUP 的表,它将映射到另一个名为 CONTENT_WORKGROUP_ROLE 的表。下面是表结构和示例数据:

CONTENT_WORKGROUP

  1. CM_WORKGROUP_ID NUMBER(15,0)
  2. WORKGROUP_ID NUMBER(15,0
  3. ) ROLE_ID VARCHAR2(20 BYTE)

CONTENT_WORKGROUP_ROLE

  1. CM_WORKGROUP_ROLE_ID NUMBER(
  2. 15,0) ROLE_ID VARCHAR2(20 BYTE)
  3. 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

  1. CM_WORKGROUP_ID NUMBER(15,0)
  2. WORKGROUP_ID NUMBER(15,0)
  3. ROLE_ID VARCHAR2(20 BYTE)

CONTENT_WORKGROUP_ROLE

  1. CM_WORKGROUP_ROLE_ID NUMBER(15,0)
  2. ROLE_ID VARCHAR2(20 BYTE)
  3. 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 技术交流群。

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

发布评论

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

评论(1

从来不烧饼 2024-10-11 02:33:10

抱歉,显示器似乎有点问题。我在这里再写一遍:

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" />
        <generator class="corp.celcom.next.util.MultipleTableGenerator" >
            <param name="KEYTABLE_VALUE">CM_WORKGROUP</param>
            <param name="KEYCOLUMN_VALUE">CM_WORKGROUP_ID</param>
        </generator>
    </id>
    <property name="workgroupId" type="long">
        <column name="WORKGROUP_ID" precision="15" scale="0" not-null="true" />
    </property>
    <property name="srId" type="string">
        <column name="SR_ID" length="15" not-null="true" />
    </property>
    <property name="contentCategoryId" type="string">
        <column name="CONTENT_CATEGORY_ID" length="40" not-null="true" />
    </property>
    <property name="roleId" type="string">
        <column name="ROLE_ID" length="20" not-null="true" />
    </property>
    <set name="contentWorkgroupRole" table="CM_WORKGROUP_ROLE" inverse="true">
        <key>
            <column name="ROLE_ID" length="20" not-null="true" />
        </key>
        <one-to-many class="corp.celcom.next.infochannel.model.ContentWorkgroupRole" />
    </set>        
</class>

ContentWorkgroupRole.hbm.xml

<hibernate-mapping>
<class name="corp.celcom.next.infochannel.model.ContentWorkgroupRole" table="CM_WORKGROUP_ROLE" >
    <id name="cmWorkgroupRoleId" type="long">
        <column name="CM_WORKGROUP_ROLE_ID" precision="15" scale="0" />
        <generator class="corp.celcom.next.util.MultipleTableGenerator">
            <param name="KEYCOLUMN_VALUE">CM_WORKGROUP_ROLE_ID</param>
            <param name="KEYTABLE_VALUE">CM_WORKGROUP_ROLE</param>
        </generator>
    </id>

    <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>

    <property name="menuId" type="string">
        <column name="MENU_ID" length="40" not-null="true" />
    </property>
    <property name="functionId" type="string">
        <column name="FUNCTION_ID" length="40" not-null="true" />
    </property> 

在我的 ACTION 类中,这一行发生了上述错误:
迭代器 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);
 }
}

Sorry, the display seem got abit problem. I write again here:

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" />
        <generator class="corp.celcom.next.util.MultipleTableGenerator" >
            <param name="KEYTABLE_VALUE">CM_WORKGROUP</param>
            <param name="KEYCOLUMN_VALUE">CM_WORKGROUP_ID</param>
        </generator>
    </id>
    <property name="workgroupId" type="long">
        <column name="WORKGROUP_ID" precision="15" scale="0" not-null="true" />
    </property>
    <property name="srId" type="string">
        <column name="SR_ID" length="15" not-null="true" />
    </property>
    <property name="contentCategoryId" type="string">
        <column name="CONTENT_CATEGORY_ID" length="40" not-null="true" />
    </property>
    <property name="roleId" type="string">
        <column name="ROLE_ID" length="20" not-null="true" />
    </property>
    <set name="contentWorkgroupRole" table="CM_WORKGROUP_ROLE" inverse="true">
        <key>
            <column name="ROLE_ID" length="20" not-null="true" />
        </key>
        <one-to-many class="corp.celcom.next.infochannel.model.ContentWorkgroupRole" />
    </set>        
</class>

ContentWorkgroupRole.hbm.xml

<hibernate-mapping>
<class name="corp.celcom.next.infochannel.model.ContentWorkgroupRole" table="CM_WORKGROUP_ROLE" >
    <id name="cmWorkgroupRoleId" type="long">
        <column name="CM_WORKGROUP_ROLE_ID" precision="15" scale="0" />
        <generator class="corp.celcom.next.util.MultipleTableGenerator">
            <param name="KEYCOLUMN_VALUE">CM_WORKGROUP_ROLE_ID</param>
            <param name="KEYTABLE_VALUE">CM_WORKGROUP_ROLE</param>
        </generator>
    </id>

    <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>

    <property name="menuId" type="string">
        <column name="MENU_ID" length="40" not-null="true" />
    </property>
    <property name="functionId" type="string">
        <column name="FUNCTION_ID" length="40" not-null="true" />
    </property> 

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);
 }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文