-->
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: many-to-many schemaexport problem with primary key
PostPosted: Sun Aug 01, 2004 7:01 pm 
Regular
Regular

Joined: Sun Aug 01, 2004 6:49 pm
Posts: 76
MySQL 4.0.14-Max, Hibernate 2.1.4

I use following many-to-many setup:

User<----|Assignmnet|---->Project (see the mapping dtds below)

The problem is that the primary key for the column id in Assignment is not created in the right way, It is not set to auto_increment, but the column user_id is set to auto_increment.

mysql> show columns from Assignment;
+------------+------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+------------+------+-----+---------------------+----------------+
| id | int(11) | | | 0 | |
| manager | tinyint(1) | | | 0 | |
| ctime | datetime | | | 0000-00-00 00:00:00 | |
| project_id | int(11) | | PRI | 0 | |
| user_id | int(11) | | PRI | NULL | auto_increment |
+------------+------------+------+-----+---------------------+----------------+


Do you have tips for this?
Thanks in advance
Thomas


-------------------------User

<?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="com.crapoud.ttraq.om.User"
table="User"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="id"
column="id"
type="java.lang.Integer"
>
<generator class="native">
</generator>
</id>

<property
name="login"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="login"
length="32"
not-null="true"
unique="true"
/>

<property
name="password"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="password"
length="32"
not-null="true"
/>

<property
name="firstName"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="firstName"
length="64"
not-null="true"
/>

<property
name="lastName"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="lastName"
length="64"
not-null="true"
/>

<property
name="email"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="email"
length="96"
not-null="true"
/>

<property
name="superuser"
type="java.lang.Boolean"
update="true"
insert="true"
access="property"
column="superuser"
not-null="true"
/>

<property
name="mtime"
type="java.util.Date"
update="true"
insert="true"
access="property"
column="mtime"
length="19"
not-null="true"
/>

<property
name="ctime"
type="java.util.Date"
update="true"
insert="true"
access="property"
column="ctime"
length="19"
not-null="true"
/>

<property
name="ltime"
type="java.util.Date"
update="true"
insert="true"
access="property"
column="ltime"
length="19"
/>

<set
name="assignments"
lazy="true"
inverse="true"
cascade="all"
sort="unsorted"
>

<key
column="user_id"
>
</key>

<one-to-many
class="com.crapoud.ttraq.om.Assignment"
/>
</set>

<set
name="projects"
table="Assignment"
lazy="true"
inverse="false"
cascade="none"
sort="unsorted"
>

<key
column="user_id"
>
</key>

<many-to-many
class="com.crapoud.ttraq.om.Project"
column="project_id"
outer-join="auto"
/>

</set>

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

<key
column="user_id"
>
</key>

<one-to-many
class="com.crapoud.ttraq.om.TimeStamp"
/>
</set>

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

</class>

</hibernate-mapping>



-------------------------Assignment



<?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="com.crapoud.ttraq.om.Assignment"
table="Assignment"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="id"
column="id"
type="java.lang.Integer"
>
<generator class="native">
</generator>
</id>

<property
name="manager"
type="java.lang.Boolean"
update="true"
insert="true"
access="property"
column="manager"
not-null="true"
/>

<property
name="ctime"
type="java.util.Date"
update="true"
insert="true"
access="property"
column="ctime"
length="19"
not-null="true"
/>

<many-to-one
name="project"
class="com.crapoud.ttraq.om.Project"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
>
<column
name="project_id"
/>
</many-to-one>

<many-to-one
name="user"
class="com.crapoud.ttraq.om.User"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
>
<column
name="user_id"
/>
</many-to-one>

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

</class>

</hibernate-mapping>


-------------------------Project



<?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="com.crapoud.ttraq.om.Project"
table="Project"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="id"
column="id"
type="java.lang.Integer"
>
<generator class="native">
</generator>
</id>

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

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

<property
name="mtime"
type="java.util.Date"
update="true"
insert="true"
access="property"
column="mtime"
length="19"
not-null="true"
/>

<many-to-one
name="project"
class="com.crapoud.ttraq.om.Project"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
>
<column
name="project_id"
/>
</many-to-one>

<property
name="ctime"
type="java.util.Date"
update="true"
insert="true"
access="property"
column="ctime"
length="19"
not-null="true"
/>

<set
name="assignments"
lazy="true"
inverse="true"
cascade="all"
sort="unsorted"
>

<key
column="project_id"
>
</key>

<one-to-many
class="com.crapoud.ttraq.om.Assignment"
/>
</set>

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

<key
column="project_id"
>
</key>

<many-to-many
class="com.crapoud.ttraq.om.User"
column="user_id"
outer-join="auto"
/>

</set>

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

<key
column="project_id"
>
</key>

<one-to-many
class="com.crapoud.ttraq.om.TimeStamp"
/>
</set>

<set
name="projects"
lazy="true"
inverse="true"
cascade="all"
sort="unsorted"
>

<key
column="project_id"
>
</key>

<one-to-many
class="com.crapoud.ttraq.om.Project"
/>
</set>

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

</class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject: [SOLVED]
PostPosted: Tue Aug 03, 2004 6:11 pm 
Regular
Regular

Joined: Sun Aug 01, 2004 6:49 pm
Posts: 76
Ok. I have found the solution <idbag...> is what I needed.

See here for details:
http://www.hibernate.org/hib_docs/reference/en/html_single/#collections-idbag


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.