与具有复合键的表的一对多关系

时间:2011-09-30 17:26:52

标签: hibernate-mapping

这是我正在进行的表的映射的完整代码。但不知道我为什么会这样 java堆空间错误。我正在使用Jboss服务器,确切的错误消息是java.lang.OutOfMemoryError:Java堆空间。

package com.mercer.chat.app.dataobject;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class MHRContChatSessionDO {


    private Long id;

    private String chatBucketHeadline;

    private String preChatLongHeadline;

    private String postChatLongHeadline;

    private String preChatSummary;

    private String postChatSummary;

    private String chatBucketImage;

    private String chatLogPath;

    private Integer roomId;

    private List<MHRContChatAlertsDO> chatAlerts;


    public MHRContChatSessionDO() {
        super();
    }

    public MHRContChatSessionDO(Long id, String chatBucketHeadline, String preChatLongHeadline,
            String postChatLongHeadline, String preChatSummary, String postChatSummary, String chatBucketImage,
            String chatLogPath,Integer roomId, List<MHRContChatAlertsDO> chatAlerts) {
        super();
        this.id = id;
        this.chatBucketHeadline = chatBucketHeadline;
        this.preChatLongHeadline = preChatLongHeadline;
        this.postChatLongHeadline = postChatLongHeadline;
        this.preChatSummary = preChatSummary;
        this.postChatSummary = postChatSummary;
        this.chatBucketImage = chatBucketImage;
        this.chatLogPath = chatLogPath;
        this.roomId = roomId;
        this.chatAlerts = chatAlerts;

    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getChatBucketHeadline() {
        return chatBucketHeadline;
    }

    public void setChatBucketHeadline(String chatBucketHeadline) {
        this.chatBucketHeadline = chatBucketHeadline;
    }

    public String getPreChatLongHeadline() {
        return preChatLongHeadline;
    }

    public void setPreChatLongHeadline(String preChatLongHeadline) {
        this.preChatLongHeadline = preChatLongHeadline;
    }

    public String getPostChatLongHeadline() {
        return postChatLongHeadline;
    }

    public void setPostChatLongHeadline(String postChatLongHeadline) {
        this.postChatLongHeadline = postChatLongHeadline;
    }

    public String getPreChatSummary() {
        return preChatSummary;
    }

    public void setPreChatSummary(String preChatSummary) {
        this.preChatSummary = preChatSummary;
    }

    public String getPostChatSummary() {
        return postChatSummary;
    }

    public void setPostChatSummary(String postChatSummary) {
        this.postChatSummary = postChatSummary;
    }

    public String getChatBucketImage() {
        return chatBucketImage;
    }

    public void setChatBucketImage(String chatBucketImage) {
        this.chatBucketImage = chatBucketImage;
    }

    public String getChatLogPath() {
        return chatLogPath;
    }

    public void setChatLogPath(String chatLogPath) {
        this.chatLogPath = chatLogPath;
    }

    public Integer getRoomId() {
        return roomId;
    }

    public void setRoomId(Integer roomId) {
        this.roomId = roomId;
    }

    public List<MHRContChatAlertsDO> getChatAlerts() {
        return chatAlerts;
    }

    public void setChatAlerts(List<MHRContChatAlertsDO> chatAlerts) {
        this.chatAlerts = chatAlerts;
    }   
}

    public class MHRContChatAlertsDO implements Serializable {

    private Long id;

    private String userId;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }


    public MHRContChatAlertsDO() {

    }

    public MHRContChatAlertsDO(Long id,String userId) {
        this.id=id;
        this.userId=userId;
    }

    @Override
    public boolean equals(Object arg0) {
        if(arg0 == null) return false;
        if(!(arg0 instanceof MHRContChatAlertsDO)) return false;
        MHRContChatAlertsDO arg1 = (MHRContChatAlertsDO) arg0;
        return (this.id.longValue() == arg1.getId().longValue()) && (this.userId.equals(arg1.getUserId())  ); 
    }
    @Override
    public int hashCode() {
        int hsCode;
        hsCode = id.hashCode();
        hsCode = 19 * hsCode+ userId.hashCode();
        return hsCode;
        }
}

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="true">
    <class name="com.mercer.chat.app.dataobject.MHRContChatSessionDO"       
        table="QA_TEST2">
            <cache usage="read-only" include="all"/>   
        <id name="id" type="java.lang.Long">
            <column name="ID_CHAT_SESSION" precision="22" scale="0" />
             <generator class="assigned" />
        </id>

        <property name="chatBucketHeadline" type="string">
                <column name="CHAT_BUCKET_HEADLINE" />
            </property>
            <property name="preChatLongHeadline" type="string">
                <column name="PRE_CHAT_LONGHEADLINE" scale="0"  />
            </property>

            <property name="postChatLongHeadline" type="string">
                <column name="POST_CHAT_LONGHEADLINE"  />
            </property>

            <property name="preChatSummary" type="string">
                <column name="PRE_CHAT_SUMMARY" />
            </property>

            <property name="postChatSummary" type="string">
                <column name="POST_CHAT_SUMMARY"  not-null="true" />
            </property>

            <property name="chatBucketImage" type="string">
                <column name="CHAT_BUCKET_IMAGE_PATH" />
            </property>

            <property name="chatLogPath" type="string">
                <column name="CHAT_LOG_PATH"  />
            </property>

            <property name="roomId" type="java.lang.Integer">
                <column name="ROOM_ID" scale="0"  />
            </property>

            <list name="chatAlerts" batch-size="5" cascade="all" lazy="false">
            <cache usage="read-only" include="all" />
            <key column="ID_CHAT_SESSION" />
            <list-index column="ID_USER" />
            <one-to-many
                class="com.mercer.chat.app.dataobject.MHRContChatAlertsDO" />
        </list>

        </class>
        </hibernate-mapping>




 <hibernate-mapping default-lazy="true">
<class name="com.mercer.chat.app.dataobject.MHRContChatAlertsDO" table="QA_TEST3">
        <cache usage="read-only" include="all" />    
        <composite-id >
        <key-property name="id" type="java.lang.Long">
                <column name="ID_CHAT_SESSION" precision="22" scale="0" />
            </key-property>
        <key-property name="userId" type="string">
                <column name="ID_USER" />
        </key-property>
        </composite-id>
            </class>
</hibernate-mapping>

0 个答案:

没有答案