-->
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: confusion with inverse="true" and inverse="fa
PostPosted: Mon Dec 13, 2004 1:17 am 
Beginner
Beginner

Joined: Thu Dec 02, 2004 4:49 am
Posts: 32
Hibernate version:2.0

Mapping documents:



<hibernate-mapping package="com.test.impl">
<class name="User" proxy="User" table="TEMP_USER">
<id name="id" type="int" unsaved-value="0" column="USER_ID">
<generator class="increment"/>
</id>
<property name="adminRole" type="true_false" column="ADMIN_ROLE"/>
<property name="userName" column="USER_NAME"/>
<set name="addresses" table="TEMP_ADDRESS" inverse="true" batch-size="20" cascade="save-update">
<key column="USER_ID"/>
<one-to-many class="Address" />
</set>
</class>
<class name="Address" table="TEMP_ADDRESS">
<id name="id" type="int" unsaved-value="0" column="ADDRESS_ID">
<generator class="increment"/>
</id>
<property name="place" column="PLACE"/>
</class>

</hibernate-mapping>




Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:DB2 7.0

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


With the above mapping document Hibernate created the tables with the following structure:

create table "NEWWMOS"."TEMP_USER" (
"USER_ID" INTEGER not null,
"ADMIN_ROLE" CHAR(1),
"USER_NAME" VARCHAR(255),
constraint "NEWWMOS"."SQL020111200745890" primary key ("USER_ID"));

create table "NEWWMOS"."TEMP_ADDRESS" (
"ADDRESS_ID" INTEGER not null,
"PLACE" VARCHAR(255),
"USER_ID" INTEGER,
constraint "NEWWMOS"."SQL020111200746040" primary key ("ADDRESS_ID"));



then I dropped the tables and changed the inverse attribute to false.
and executed the program again. The tables are created with the following structure:

create table "NEWWMOS"."TEMP_USER" (
"USER_ID" INTEGER not null,
"ADMIN_ROLE" CHAR(1),
"USER_NAME" VARCHAR(255),
constraint "NEWWMOS"."SQL020111202620620" primary key ("USER_ID"));



create table "NEWWMOS"."TEMP_ADDRESS" (
"ADDRESS_ID" INTEGER not null,
"PLACE" VARCHAR(255),
"USER_ID" INTEGER,
constraint "NEWWMOS"."SQL020111202620810" primary key ("ADDRESS_ID"), constraint "FKEA5AF6692206F20F" foreign key ("USER_ID") references "TEMP_USER" ("USER_ID"));


So foreign-key relationship is maintained when inverse="false" and not when inverse="true"...

How is it justified?
Does inverse="true" make sense only when the relation is bidirectional ie when many-to-one tag is present in the Address class tag.
If that is the case, why doesn't Hibernate throw any exception when inverse="true" is specified without any many-to-one relation?


Please help,
Thanks,
SSSS.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 13, 2004 7:18 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Quote:
Does inverse="true" make sense only when the relation is bidirectional


Yes.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 14, 2004 1:49 am 
Beginner
Beginner

Joined: Thu Dec 02, 2004 4:49 am
Posts: 32
Then why Hibernate does not throw exception when inverse is specified without any many-to-one relation?

any reasons for that?


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.