-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: the hbm.xml file of self nested table
PostPosted: Mon Sep 29, 2003 3:51 am 
Beginner
Beginner

Joined: Fri Sep 26, 2003 2:50 am
Posts: 32
now i have a hbm.xml file of a self nested table ad following:
Code:
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class name="test.Operation" table="T_Operation"
        dynamic-update="false" dynamic-insert="false">
        <id name="id" column="OperID" type="string" length="5">
            <generator class="assigned"/>
        </id>
        <property name="parentId" type="string" update="true"
            insert="true" column="ParentID" length="5"/>
        <property name="operName" type="string" update="true"
            insert="true" column="OperName" length="20"/>
        <property name="description" type="string" update="true"
            insert="true" column="Description" length="128"/>
       
        <many-to-one name="parent" class="test.Operation" cascade="none"
            outer-join="auto" update="true" insert="true" column="ParentID"
            not-null="false"/>
        <set name="operations" table="T_Operations" lazy="false"
            inverse="true" cascade="all" sort="unsorted">
              <key column="ParentID"/>
              <one-to-many class="test.Operation" />
        </set>
    </class>
</hibernate-mapping>


Code:
package com.regical.eoss.db;

import java.util.Set;

/**
* @hibernate.class table="T_Operation"
*/
public class Operation {
    private String id;
    private String parentId;
    private String operName;
    private String description;

    private Set operations;

    private Operation parent;

    /**
     * @hibernate.id generator-class="assigned" column="OperID"
     *               type="string" length="5"
     * @return
     */
    public String getId() {
        return id;
    }

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

    /**
     * @hibernate.property column="ParentID" type="string" length="5"
     * @return
     */
    public String getParentId() {
        return parentId;
    }

    public void setParentId(String id) {
        this.parentId = id;
    }

    /**
     * @hibernate.property column="OperName" type="string" length="20"
     * @return
     */
    public String getOperName() {
        return operName;
    }

    public void setOperName(String name) {
        this.operName = name;
    }

    /**
     * @hibernate.property column="Description" type="string" length="128"
     * @return
     */
    public String getDescription() {
        return this.description;
    }

    public void setDescription(String desp) {
        this.description = desp;
    }

    /**
     * @hibernate.many-to-one role="parent" column="ParentID" not-null="false"
     *                        class="com.regical.eoss.db.Operation"
     */
    public Operation getParent() {
        return parent;
    }

    public void setParent(Operation oper) {
        parent = oper;
    }

    /**
     * @hibernate.set role="ChildOpers" table="T_Operations" cascade="all"
     *                inverse="true"
     * @hibernate.collection-key column="ParentID"
     * @hibernate.collection-one-to-many class="com.regical.eoss.db.Operation"
     * @param opers
     * @return
     */
    public Set getOperations() {
        return operations;
    }

    public void setOperations(Set opers) {
        this.operations = opers;
    }
}


When i use this class to insert data to the table, hibernate throws following exception :
Code:
net.sf.hibernate.MappingException: Repeated column in mapping for class com.regical.eoss.db.Operation should be mapped with insert="false" update="false": ParentID


If I define insert="false" & update="false" for parentid attribute, the program run normally. but i check the table, I find there is no parentid data for every row.

How can i do?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 29, 2003 4:13 am 
Beginner
Beginner

Joined: Fri Sep 26, 2003 2:50 am
Posts: 32
sorry, i made a mistake.

I could not add setter&getter of attribute parentid, this attribute should be managed by the association.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.