-->
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.  [ 7 posts ] 
Author Message
 Post subject: trouble on one-to-many: father could not find children
PostPosted: Wed Jan 07, 2004 8:13 pm 
Newbie

Joined: Wed Dec 24, 2003 9:17 pm
Posts: 6
<?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 package="flybean.db.specification">
<class name="Subject" table="FST_SUBJECT">
<id name="id" column="id" type="string" length="36">
<generator class="uuid.hex" />
</id>
<property name="name" column="name" type="string" length="30" not-null="true"/>
<property name="display" column="display" type="string" length="50" not-null="true"/>
<set name="specifications" lazy="false" inverse="true" cascade="save-update">
<key column="subjectID" />
<one-to-many class="Specification" />
</set>
</class>

<class name="Specification" table="FST_SPEC">
<id name="id" column="id" type="string" length="36">
<generator class="uuid.hex" />
</id>
<property name="name" column="name" type="string" length="30" not-null="true"/>
<property name="display" column="display" type="string" length="50" not-null="true"/>
<property name="type" column="type" type="string" length="10" not-null="true"/>
<property name="length" column="length" type="integer"/>
<property name="scale" column="scale" type="integer"/>
<property name="dispSeq" column="dispSeq" type="integer"/>
<property name="specType" column="specType" type="string" length="10"/>
<many-to-one name="subject" column="subjectID" class="Subject" not-null="true" out-join="false"/>

<joined-subclass name="Column" table="FST_COLUMN">
<key column="id"/>
<property name="database" column="dbName" type="string" length="50"/>
<property name="schema" column="schName" type="string" length="50"/>
<property name="table" column="tblName" type="string" length="50" not-null="true"/>
<property name="topic" column="topicName" type="string" length="50"/>
<property name="data" column="topicDataName" type="string" length="20"/>
<property name="value" column="topicValueName" type="string" length="20"/>
</joined-subclass>

<joined-subclass name="ComputedField" table="FST_FORMULA">
<key column="id"/>
<property name="formula" column="formula" type="string" length="1000" not-null="true"/>
</joined-subclass>
</class>
</hibernate-mapping>

=============================================

DBMS : ORACLE9i

create table FST_SUBJECT (
id CHAR(36) not null,
name VARCHAR(30) not null,
display VARCHAR(50) not null,
constraint PK_FST_SUBJECT primary key (id)
)
/

create table FST_SPEC (
id CHAR(36) not null,
subjectID CHAR(36) not null,
name VARCHAR(30) not null,
display VARCHAR(50) not null,
type VARCHAR(10) not null,
length INTEGER,
scale SMALLINT,
dispSeq SMALLINT,
specType VARCHAR(20) not null,
constraint PK_FST_SPEC primary key (id),
constraint FK_FST_SPEC_REFERENCE_FST_SUBJ foreign key (subjectID)
references FST_SUBJECT (id)
)

create table FST_COLUMN (
id CHAR(36) not null,
dbName VARCHAR(50),
schName VARCHAR(50),
tblName VARCHAR(50) not null,
topicName VARCHAR(50),
topicDataName VARCHAR(20),
topicValueName VARCHAR(20),
constraint PK_FST_COLUMN primary key (id),
constraint FK_FST_COLU_REFERENCE_FST_SPEC foreign key (id)
references FST_SPEC (id)
)

create table FST_FORMULA (
id CHAR(36) not null,
formula VARCHAR(1000) not null,
constraint PK_FST_FORMULA primary key (id),
constraint FK_FST_FORM_REFERENCE_FST_SPEC foreign key (id)
references FST_SPEC (id)
)

Mapping info from Hibernate:
23:15:21,784 INFO Binder:225 - Mapping class: flybean.db.specification.Subject -> FST_SUBJECT
23:15:22,225 DEBUG Binder:449 - Mapped property: id -> id, type: string
23:15:22,445 DEBUG Binder:449 - Mapped property: name -> name, type: string
23:15:22,455 DEBUG Binder:449 - Mapped property: display -> display, type: string
23:15:22,685 DEBUG Binder:449 - Mapped property: specifications, type: java.util.Set
23:15:22,695 INFO Binder:225 - Mapping class: flybean.db.specification.Specification -> FST_SPEC
23:15:22,705 DEBUG Binder:449 - Mapped property: id -> id, type: string
23:15:22,715 DEBUG Binder:449 - Mapped property: name -> name, type: string
23:15:22,725 DEBUG Binder:449 - Mapped property: display -> display, type: string
23:15:22,735 DEBUG Binder:449 - Mapped property: type -> type, type: string
23:15:22,745 DEBUG Binder:449 - Mapped property: length -> length, type: integer
23:15:22,755 DEBUG Binder:449 - Mapped property: scale -> scale, type: integer
23:15:22,936 DEBUG Binder:449 - Mapped property: dispSeq -> dispSeq, type: integer
23:15:22,956 DEBUG Binder:449 - Mapped property: specType -> specType, type: string
23:15:22,976 DEBUG Binder:449 - Mapped property: subject -> subjectID, type: flybean.db.specification.Subject
23:15:23,396 INFO Binder:200 - Mapping joined-subclass: flybean.db.specification.Column -> FST_COLUMN
23:15:23,406 DEBUG Binder:449 - Mapped property: database -> dbName, type: string
23:15:23,416 DEBUG Binder:449 - Mapped property: schema -> schName, type: string
23:15:23,456 DEBUG Binder:449 - Mapped property: table -> tblName, type: string
23:15:23,536 DEBUG Binder:449 - Mapped property: topic -> topicName, type: string
23:15:23,556 DEBUG Binder:449 - Mapped property: data -> topicDataName, type: string
23:15:23,566 DEBUG Binder:449 - Mapped property: value -> topicValueName, type: string
23:15:23,607 INFO Binder:200 - Mapping joined-subclass: flybean.db.specification.ComputedField -> FST_FORMULA
23:15:23,617 DEBUG Binder:449 - Mapped property: formula -> formula, type: string

SQL that hibernate built:
23:15:38,949 DEBUG SQL:223 - select specificat0_.id as id__, subject1_.id as id0_, subject1_.name as name0_, subject1_.display as display0_, specificat0_.id as id1_, case when specificat0__1_.id is not null then 1 when specificat0__2_.id is not null then 2 when specificat0_.id is not null then 0 end as clazz_1_, specificat0_.name as name1_1_, specificat0_.display as display1_1_, specificat0_.type as type1_1_, specificat0_.length as length1_1_, specificat0_.scale as scale1_1_, specificat0_.dispSeq as dispSeq1_1_, specificat0_.specType as specType1_1_, specificat0_.subjectID as subjectID1_1_, specificat0__1_.dbName as dbName2_1_, specificat0__1_.schName as schName2_1_, specificat0__1_.tblName as tblName2_1_, specificat0__1_.topicName as topicName2_1_, specificat0__1_.topicDataName as topicDat6_2_1_, specificat0__1_.topicValueName as topicVal7_2_1_, specificat0__2_.formula as formula3_1_ from FST_SPEC specificat0_ left outer join FST_COLUMN specificat0__1_ on specificat0_.id=specificat0__1_.id left outer join FST_FORMULA specificat0__2_ on specificat0_.id=specificat0__2_.id left outer join FST_SUBJECT subject1_ on specificat0_.subjectID=subject1_.id where specificat0_.id=?
Hibernate: select specificat0_.id as id__, subject1_.id as id0_, subject1_.name as name0_, subject1_.display as display0_, specificat0_.id as id1_, case when specificat0__1_.id is not null then 1 when specificat0__2_.id is not null then 2 when specificat0_.id is not null then 0 end as clazz_1_, specificat0_.name as name1_1_, specificat0_.display as display1_1_, specificat0_.type as type1_1_, specificat0_.length as length1_1_, specificat0_.scale as scale1_1_, specificat0_.dispSeq as dispSeq1_1_, specificat0_.specType as specType1_1_, specificat0_.subjectID as subjectID1_1_, specificat0__1_.dbName as dbName2_1_, specificat0__1_.schName as schName2_1_, specificat0__1_.tblName as tblName2_1_, specificat0__1_.topicName as topicName2_1_, specificat0__1_.topicDataName as topicDat6_2_1_, specificat0__1_.topicValueName as topicVal7_2_1_, specificat0__2_.formula as formula3_1_ from FST_SPEC specificat0_ left outer join FST_COLUMN specificat0__1_ on specificat0_.id=specificat0__1_.id left outer join FST_FORMULA specificat0__2_ on specificat0_.id=specificat0__2_.id left outer join FST_SUBJECT subject1_ on specificat0_.subjectID=subject1_.id where specificat0_.id=?

why "where specifiact0_.id = ?" ?
Should be "subject1_.id = ?",

_________________
Can fly means free.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2004 8:20 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
What HQL query caused this? Or what have you attempted to load?


Top
 Profile  
 
 Post subject: Just use simple Criteria
PostPosted: Wed Jan 07, 2004 9:48 pm 
Newbie

Joined: Wed Dec 24, 2003 9:17 pm
Posts: 6
dimas wrote:
What HQL query caused this? Or what have you attempted to load?


List subjects = session.createCriteria( Subject.class ).list();
Iterator it = subjects.iterator();

while ( it.hasNext() ) {
Subject subject = ( Subject ) it.next();
logger.info( subject.getSpecifications().size() );
}

the logger logs as zero.

And I made a simple test : ( on Sybase, the above is on Oracle 9i )
<class name="Test1" table="test1">
<id name="id" column="id" type="string" length="36">
<generator class="assigned"/>
</id>
<property name="name" column="name" type="string" length="50"/>
<set name="test2" cascade="all" inverse="true" lazy="true">
<key column="parentid"/>
<one-to-many class="Test2"/>
</set>
</class>

<class name="Test2" table="test2">
<id name="id" column="id" type="string" length="36">
<generator class="assigned"/>
</id>
<property name="note" column="note" type="string" length="50"/>
<many-to-one name="test1" class="Test1" not-null="true">
<column name="parentid" />
</many-to-one>
</class>

this one is OK.

And when I refer to the DTD, I noticed that there is a new attribute "foregin-key" in the "many-to-one" element, but the reference document dose not write it out . Any usage of this new attribute?

Thanks a lot.

_________________
Can fly means free.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2004 9:00 am 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
1. there is no "out-join" attribute but "outer-join". I have no idea why your code works because my attempt to run it causes MappingException

2. What Hibernate version are you using? I have your maping (with all properties except for associations) removed and it works fine: "... where specificat0_.subjectID=?"


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2004 9:12 am 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
Forgot to say, I tried this on HB 2.1.1


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2004 8:32 pm 
Newbie

Joined: Wed Dec 24, 2003 9:17 pm
Posts: 6
dimas wrote:
Forgot to say, I tried this on HB 2.1.1

Yes, "out-join" attribute is not correct. But even remove it( the orgin version dhas not set this attribute), it works not right.

I use HB 2.1.1 too.

What your mean is removing the associations?

_________________
Can fly means free.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 09, 2004 9:14 am 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
1. I took your mapping
2. removed all properties except for identifiers, associations (one-to-many, many-to-one, sets etc)
3. Created very simple beans which have all these ids and associations.
4. Run the code.
Code:
List subjects = session.createCriteria( Subject.class ).list();

5. Got completely different SELECT statements

From that I assume the SELECT you pasted here is generated from another part of the code OR your classes has some logic in the property setters which causes Hibernate to perform some additional loading. Or comething like that.

I suggest you to create SIMPLEST POSSIBLE test containing the only main() method which does

Code:
List subjects = session.createCriteria( Subject.class ).list();


and see what happens.


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