-->
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.  [ 4 posts ] 
Author Message
 Post subject: wrong columns for the many-to-many table in Schema Export
PostPosted: Tue Jul 06, 2004 2:52 am 
Beginner
Beginner

Joined: Mon May 17, 2004 7:15 am
Posts: 24
My simplified domain model consists of tree classes: TreeNode, IndustryNode inheriting the TreeNode, and Enterprise. And their relationships are modeled as many-to-many between IndustryNode and Enterprise, joined-subclass between TreeNode and IndustryNode.

And the mapping file is
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="domain.common.tree.TreeNode"
        table="QBS_TREENODE"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="objID"
            column="TREENODE_OBJID"
            type="java.lang.String"
            length="32"
        >
            <generator class="uuid.hex">
            </generator>
        </id>

        <property
            name="nodeData"
            type="java.lang.String"
            update="true"
            insert="true"
        >
            <column
                name="TN_DATA"
                length="256"
            />
        </property>

        <many-to-one
            name="parentNode"
            class="domain.common.tree.TreeNode"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            column="FK_TN_PARENT_ID"
        />

        <many-to-one
            name="tree"
            class="domain.common.tree.Tree"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            column="FK_TREE_ID"
        />

        <joined-subclass
            name="domain.enterprise.industry.IndustryNode"
            table="QBS_TREENODE_INDUSTRY"
            dynamic-update="false"
            dynamic-insert="false"
        >
        <key
            column="TN_OBJID"
        />
        <property
            name="industryName"
            type="java.lang.String"
            update="true"
            insert="true"
        >
            <column
                name="IN_NAME"
                length="128"
            />
        </property>

        <property
            name="industryCode"
            type="java.lang.String"
            update="true"
            insert="true"
        >
            <column
                name="IN_CODE"
                length="128"
            />
        </property>

        <bag
            name="enterprises"
            table="QBS_JOIN_ENTERPRISE_INDUSTRYNODE"
            lazy="true"
            inverse="false"
            cascade="delete"
        >

              <key
                  column="TN_OBJID"
              />

              <many-to-many
                  class="domain.enterprise.Enterprise"
                  column="FK_ENTER_ID"
                  outer-join="auto"
              />

        </bag>

        </joined-subclass>

    </class>

  <class
        name="domain.enterprise.Enterprise"
        table="QBS_ENTERPRISE"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="objID"
            column="ENTER_OBJID"
            type="java.lang.String"
            length="32"
        >
            <generator class="uuid.hex">
            </generator>
        </id>

        <property
            name="enterName"
            type="java.lang.String"
            update="true"
            insert="true"
        >
            <column
                name="ENTER_NAME"
                length="128"
                not-null="true"
            />
        </property>

         <bag
            name="industries"
            table="QBS_JOIN_ENTERPRISE_INDUSTRYNODE"
            lazy="true"
            inverse="false"
            cascade="delete"
        >

              <key
                  column="FK_ENTER_ID"
              />

              <many-to-many
                  class="domain.enterprise.industry.IndustryNode"
                  column="TN_OBJID"
                  outer-join="auto"
              />

        </bag>

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-Enterprise.xml
            containing the additional properties and place it in your merge dir.
        -->

    </class>

</hibernate-mapping>


The DDL exported is
Quote:

14:21:35,579 DEBUG SchemaExport:149 - create table QBS_ENTERPRISE (
ENTER_OBJID VARCHAR(32) not null,
ENTER_NAME VARCHAR(128) not null,
primary key (ENTER_OBJID)
)
14:21:35,599 DEBUG SchemaExport:149 - create table QBS_JOIN_ENTERPRISE_INDUSTRYNODE (
FK_ENTER_ID VARCHAR(32) not null,
TN_OBJID VARCHAR(255) not null
)
14:21:35,900 DEBUG SchemaExport:149 - create table QBS_TREENODE_INDUSTRY (
TN_OBJID VARCHAR(32) not null,
IN_NAME VARCHAR(128) null,
IN_CODE VARCHAR(128) null,
primary key (TN_OBJID)
)
14:21:38,664 DEBUG SchemaExport:149 - create table QBS_TREENODE (
TREENODE_OBJID VARCHAR(32) not null,
TN_DATA VARCHAR(256) null,
FK_TN_PARENT_ID VARCHAR(32) null,
primary key (TREENODE_OBJID)
)

So I got errors when creating the constraint as:
Quote:
14:21:38,974 ERROR SchemaExport:154 - Unsuccessful: alter table QBS_JOIN_ENTERPRISE_INDUSTRYNODE add constraint FK78568BA6DA9D8A2D foreign key (TN_OBJID) references QBS_TREENODE_INDUSTRY


The Schema Export creates the column TN_OBJID of the joined table with 255 rather the length of the indentifer of IndustryNode. Do you guys think it is a bug? or Is there something wrong?

Regards,

James.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 06, 2004 8:51 am 
Beginner
Beginner

Joined: Mon May 17, 2004 7:15 am
Posts: 24
Could any Hibernate expert tell me what is wrong with my mapping?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 06, 2004 12:15 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You should add length="32" to the key element
Code:
<many-to-many
                  class="domain.enterprise.industry.IndustryNode"
                  column="TN_OBJID"
                  outer-join="auto"
                   length="32"
              />


and you should not have inverse="false" at both end

_________________
Emmanuel


Top
 Profile  
 
 Post subject: doesn't work in all cases for me
PostPosted: Mon Mar 28, 2005 4:49 pm 
Newbie

Joined: Thu Feb 17, 2005 11:50 pm
Posts: 4
I ran into the same problem in more complex problem and when I added the length attribute the key-column, it solved one of the two instances of the problem.
I have two many-to-many mappings: User-Group and Group-Role.
Adding the length attribute works for the Group-Role mapping.
The only way that the link tables are generated corretly (both varchar-255) is if Group specifies inverse="true" for both of its sets.
I thought that the inverse side of the relationship was supposed to be arbitrary.
Please correct me if I'm wrong, but doesn't this mean that the inverse is not arbitrary?

I'll present my mappings in the way that they work, but if you move the inverse="true" from JitUser to JitGroup (for the User-Group many-to-many), then the FK userForGroup in the link table is a varchar(255).

Any ideas?

Thanks in advance
-Trey

Code:
<hibernate-mapping>
    <class
        name="com.digilore.model.bean.JitUser"
        table="JitUser"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="id"
            column="id"
            type="java.lang.String"
            length="32"
            unsaved-value="null"
        >
            <generator class="uuid.hex">
            </generator>
        </id>

        <set
            name="groups"
            table="JitUser_JitGroup"
            lazy="false"
            inverse="true"
            cascade="none"
            sort="unsorted"
        >

              <key
              >
                <column
                    name="userForGroup"
                    length="32"
                />
              </key>

              <many-to-many
                  class="com.digilore.model.bean.JitGroup"
                  column="groupForUser"
                  outer-join="auto"
               />

        </set>

        <property
            name="userName"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="userName"
        />

    </class>
</hibernate-mapping>

<hibernate-mapping>
    <class
        name="com.digilore.model.bean.JitGroup"
        table="JitGroup"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="id"
            column="id"
            type="java.lang.String"
            length="32"
            unsaved-value="null"
        >
            <generator class="uuid.hex">
            </generator>
        </id>

        <set
            name="roles"
            table="JitGroup_JitRole"
            lazy="false"
            inverse="false"
            cascade="none"
            sort="unsorted"
        >

              <key
              >
                <column
                    name="groupForRole"
                    length="32"
                />
              </key>

              <many-to-many
                  class="com.digilore.model.bean.JitRole"
                  column="roleForGroup"
                  outer-join="auto"
               />

        </set>

        <set
            name="users"
            table="JitUser_JitGroup"
            lazy="false"
            inverse="false"
            cascade="none"
            sort="unsorted"
        >

              <key
              >
                <column
                    name="groupForUser"
                    length="32"
                />
              </key>

              <many-to-many
                  class="com.digilore.model.bean.JitUser"
                  column="userForGroup"
                  outer-join="auto"
               />

        </set>

        <property
            name="title"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="title"
        />

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-JitGroup.xml
            containing the additional properties and place it in your merge dir.
        -->

    </class>
</hibernate-mapping>

<hibernate-mapping>
    <class
        name="com.digilore.model.bean.JitRole"
        table="JitRole"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="id"
            column="id"
            type="java.lang.String"
            length="32"
            unsaved-value="null"
        >
            <generator class="uuid.hex">
            </generator>
        </id>

        <set
            name="groups"
            table="JitGroup_JitRole"
            lazy="false"
            inverse="true"
            cascade="none"
            sort="unsorted"
        >

              <key
              >
                <column
                    name="roleForGroup"
                    length="32"
                />
              </key>

              <many-to-many
                  class="com.digilore.model.bean.JitGroup"
                  column="groupForRole"
                  outer-join="auto"
               />

        </set>

        <set
            name="permissions"
            lazy="false"
            inverse="true"
            cascade="none"
            sort="unsorted"
        >

              <key
                  column="role"
              >
              </key>

              <one-to-many
                  class="com.digilore.model.bean.JitPermission"
              />
        </set>

        <property
            name="title"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="title"
        />

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-JitRole.xml
            containing the additional properties and place it in your merge dir.
        -->

    </class>
</hibernate-mapping>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.