-->
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.  [ 3 posts ] 
Author Message
 Post subject: many-to-any and schema export
PostPosted: Sat Oct 22, 2005 12:45 pm 
Newbie

Joined: Wed Jul 13, 2005 5:36 am
Posts: 7
Hello.

I have a many-to-any mapping but the association table that schema export generates is wrong (see below):

Hibernate version:
3.0.5
Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="mypackage">
<class
    name="Task"
    table="task"
    proxy="Task"
>
     <id name="id" type="java.lang.Long" column="id">
<generator class="native"/>
     </id>

    <version name="version" column="version"/>   
    <property
        name="name"
        type="java.lang.String"
        column="name"
        not-null="true"
        length="250"
    >
       
<!-- uni-directional many-to-any association -->
    <set
        name="taskObjects"
        lazy="true"
cascade="none"
table="task_obj_assoc"
    >
    <key column="task_id"/>
        <many-to-any id-type="long">
            <column name="ref_type"/>
            <column name="ref_id"/>
</many-to-any>
    </set>
</class>
</hibernate-mapping>


Name and version of the database you are using:
MySQL 4.1.12 (InnoDB)

The generated "task_obj_assoc" table has the following structure:
+------+ +---------------------+
| task | | task_obj_assoc |
+------+ +---------------------+
| id | <-------> | task_id (PK) (FK) |
| | | ref_type |
+------+ | ref_id |
+---------------------+

The problem is that the id of task_obj_assoc should be a composite key (made out of task_id, ref_type and ref_id) not just task_id (it's a not a many-to-many relationship anymore but 1 (task side)-to-many).

Is this a bug or am I missing something here? Is there a workaround or is my mapping incorrect? I have searched the tests/docs/forum plus DTD and I couldn't find another attribute/element to add.

Thanks!

_________________
--
Costin


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 24, 2005 4:53 am 
Newbie

Joined: Wed Jul 13, 2005 5:36 am
Posts: 7
My ascii drawing is mixed up - here is a proper one (I hope):

Code:
+------+               +----------------------+
| task |               | task_obj_assoc       |
+------+               +----------------------+
| id   |  <------->    | task_id (PK) (FK)    |
|      |               | ref_type             |
+------+               | ref_id               |
                       +----------------------+

_________________
--
Costin


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 27, 2005 2:38 am 
Newbie

Joined: Wed Jul 13, 2005 5:36 am
Posts: 7
Thanks to Gavin for pointing out not-null:

http://opensource2.atlassian.com/projec ... e/HHH-1089

<many-to-any id-type="long">
<column name="ref_type" not-null="true"/>
<column name="ref_id" not-null="true"/>
</many-to-any>

makes the columns to be included inside the primary.

_________________
--
Costin


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