-->
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: Incorrect id
PostPosted: Fri Feb 20, 2004 9:35 pm 
Newbie

Joined: Fri Feb 20, 2004 9:03 pm
Posts: 5
Location: Montreal, QC
Hibernate version: 2.1.2

Mapping documents:
CategoryBean
<hibernate-mapping>
<class name="com.elendal.jFF.model.CategoryBean" lazy="true" table="category">
<id name="id" type="int">
<generator class="native"/>
</id>
<property name="title" column="title" type="string" not-null="true"/>
<property name="description" column="description" type="string" not-null="true"/>
<set name="boards" table="board">
<key column="cat_id"/>
<one-to-many class="com.elendal.jFF.model.BoardBean"/>
</set>
</class>
</hibernate-mapping>

BoardBean

<hibernate-mapping>
<class name="com.elendal.jFF.model.BoardBean" lazy="true" table="board">
<id column="id" type="int">
<generator class="native"/>
</id>
<property name="num_threads" column="num_threads" type="int" not-null="true"/>
<property name="title" column="title" type="string" not-null="true"/>
<property name="description" column="description" type="string" not-null="true"/>
<many-to-one name="category" class="com.elendal.jFF.model.CategoryBean" column="cat_id"/>
<set name="threads" table="THREAD_GROUP" lazy="true">
<key column="board_id"/>
<one-to-many class="com.elendal.jFF.model.ThreadGroupBean"/>
</set>
</class>
</hibernate-mapping>


Java Code small sample

List categories;
categories = session.createCriteria(CategoryBean.class)
.setFirstResult(0)
.setMaxResults(10)
.list();
CategoryBean categoryBean = (CategoryBean) (categories.toArray()[0]);
BoardBean bb =(BoardBean)categoryBean.getBoards().toArray()[0];
logger.info(new Integer(bb.getId()));

Database: Oracle 9i

Hibernate log
2004-02-20 20:12:44,371 DEBUG net.sf.hibernate.impl.SessionImpl.<init>(SessionImpl.java:531) : opened session
2004-02-20 20:12:44,380 DEBUG net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2210) : flushing session
2004-02-20 20:12:44,382 DEBUG net.sf.hibernate.impl.SessionImpl.flushEntities(SessionImpl.java:2403) : Flushing entities and processing referenced collections
2004-02-20 20:12:44,384 DEBUG net.sf.hibernate.impl.SessionImpl.flushCollections(SessionImpl.java:2746) : Processing unreferenced collections
2004-02-20 20:12:44,386 DEBUG net.sf.hibernate.impl.SessionImpl.flushCollections(SessionImpl.java:2760) : Scheduling collection removes/(re)creates/updates
2004-02-20 20:12:44,387 DEBUG net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2234) : Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects
2004-02-20 20:12:44,389 DEBUG net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2239) : Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
2004-02-20 20:12:44,391 DEBUG net.sf.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1782) : Dont need to execute flush
2004-02-20 20:12:44,393 DEBUG net.sf.hibernate.impl.BatcherImpl.logOpenPreparedStatement(BatcherImpl.java:196) : about to open: 0 open PreparedStatements, 0 open ResultSets
2004-02-20 20:12:44,436 DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:78) : total checked-out connections:
0
2004-02-20 20:12:44,441 DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:84) : using pooled JDBC connection,
pool size: 0
2004-02-20 20:12:44,688 DEBUG net.sf.hibernate.impl.BatcherImpl.getPreparedStatement(BatcherImpl.java:237) : select * from ( select this.id as id0_, this.title as title0_, this.
description as descript3_0_ from category this where 1=1 ) where rownum <= ?
2004-02-20 20:12:44,690 DEBUG net.sf.hibernate.impl.BatcherImpl.getPreparedStatement(BatcherImpl.java:241) : preparing statement
2004-02-20 20:12:44,704 DEBUG net.sf.hibernate.loader.Loader.doQuery(Loader.java:197) : processing result set
2004-02-20 20:12:44,708 DEBUG net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:68) : returning '4' as column: id0_
2004-02-20 20:12:44,710 DEBUG net.sf.hibernate.loader.Loader.getRow(Loader.java:405) : result row: 4
2004-02-20 20:12:44,713 DEBUG net.sf.hibernate.loader.Loader.loadFromResultSet(Loader.java:536) : Initializing object from ResultSet: 4
2004-02-20 20:12:44,716 DEBUG net.sf.hibernate.loader.Loader.hydrate(Loader.java:605) : Hydrating entity: com.elendal.jFF.model.CategoryBean#4
2004-02-20 20:12:44,718 DEBUG net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:68) : returning 'Java world' as column: title0_
2004-02-20 20:12:44,732 DEBUG net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:68) : returning 'Place where programers make magic' as column: descript3_0_
2004-02-20 20:12:44,735 DEBUG net.sf.hibernate.loader.Loader.doQuery(Loader.java:226) : done processing result set (1 rows)
2004-02-20 20:12:44,740 DEBUG net.sf.hibernate.impl.BatcherImpl.logClosePreparedStatement(BatcherImpl.java:203) : done closing: 0 open PreparedStatements, 0 open ResultSets
2004-02-20 20:12:44,743 DEBUG net.sf.hibernate.impl.BatcherImpl.closePreparedStatement(BatcherImpl.java:261) : closing statement
2004-02-20 20:12:44,747 DEBUG net.sf.hibernate.loader.Loader.doQuery(Loader.java:239) : total objects hydrated: 1
2004-02-20 20:12:44,749 DEBUG net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:2166) : resolving associations for [com.elendal.jFF.model.Category
Bean#4]
2004-02-20 20:12:44,752 DEBUG net.sf.hibernate.impl.SessionImpl.getCollection(SessionImpl.java:3891) : creating collection wrapper:[com.elendal.jFF.model.CategoryBe
an.boards#4]
2004-02-20 20:12:44,755 DEBUG net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:2182) : calling onLoad()
2004-02-20 20:12:44,757 DEBUG net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:2190) : done materializing entity [com.elendal.jFF.model.CategoryB
ean#4]
2004-02-20 20:12:44,759 DEBUG net.sf.hibernate.impl.SessionImpl.initializeNonLazyCollections(SessionImpl.java:3082) : initializing non-lazy collections
2004-02-20 20:12:44,761 DEBUG net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:3218) : initializing collection [com.elendal.jFF.model.Categor
yBean.boards#4]
2004-02-20 20:12:44,767 DEBUG net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:3219) : checking second-level cache
2004-02-20 20:12:44,776 DEBUG net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:3225) : collection not cached
2004-02-20 20:12:44,780 DEBUG net.sf.hibernate.impl.BatcherImpl.logOpenPreparedStatement(BatcherImpl.java:196) : about to open: 0 open PreparedStatements, 0 open ResultSets
2004-02-20 20:12:44,782 DEBUG net.sf.hibernate.impl.BatcherImpl.getPreparedStatement(BatcherImpl.java:237) : select boards0_.id as id__, boards0_.cat_id as cat_id__, boards0_.id
as id0_, boards0_.num_threads as num_thre2_0_, boards0_.title as title0_, boards0_.description as descript4_0_, boards0_.cat_id as cat_id0_ from board boards0_ where boards0_.c
at_id=?
2004-02-20 20:12:44,784 DEBUG net.sf.hibernate.impl.BatcherImpl.getPreparedStatement(BatcherImpl.java:241) : preparing statement
2004-02-20 20:12:44,789 DEBUG net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:46) : binding '4' to parameter: 1
2004-02-20 20:12:44,806 DEBUG net.sf.hibernate.loader.Loader.handleEmptyCollections(Loader.java:327) : result set contains (possibly empty) collection: [com.elendal.jFF.model.CategoryBean.boards#4]
2004-02-20 20:12:44,808 DEBUG net.sf.hibernate.impl.SessionImpl.getLoadingCollection(SessionImpl.java:2984) : uninitialized collection: initializing
2004-02-20 20:12:44,812 DEBUG net.sf.hibernate.loader.Loader.doQuery(Loader.java:197) : processing result set
2004-02-20 20:12:44,814 DEBUG net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:68) : returning '5' as column: id0_
2004-02-20 20:12:44,816 DEBUG net.sf.hibernate.loader.Loader.getRow(Loader.java:405) : result row: 5
2004-02-20 20:12:44,818 DEBUG net.sf.hibernate.loader.Loader.loadFromResultSet(Loader.java:536) : Initializing object from ResultSet: 5
2004-02-20 20:12:44,820 DEBUG net.sf.hibernate.loader.Loader.hydrate(Loader.java:605) : Hydrating entity: com.elendal.jFF.model.BoardBean#5
2004-02-20 20:12:44,827 DEBUG net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:68) : returning '3' as column: num_thre2_0_
2004-02-20 20:12:44,830 DEBUG net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:68) : returning 'J2SE' as column: title0_
2004-02-20 20:12:44,833 DEBUG net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:68) : returning 'Write once debug everywere' as column: descript4_0_
2004-02-20 20:12:44,835 DEBUG net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:68) : returning '4' as column: cat_id0_
2004-02-20 20:12:44,841 DEBUG net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:68) : returning '4' as column: cat_id__
2004-02-20 20:12:44,843 DEBUG net.sf.hibernate.loader.Loader.readCollectionElement(Loader.java:292) : found row of collection: [com.elendal.jFF.model.CategoryBean.b
oards#4]
2004-02-20 20:12:44,845 DEBUG net.sf.hibernate.impl.SessionImpl.getLoadingCollection(SessionImpl.java:3007) : reading row
2004-02-20 20:12:44,847 DEBUG
net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:68) : returning '5' as column: id__
2004-02-20 20:12:44,849 DEBUG net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1950) : loading [com.elendal.jFF.model.BoardBean#5]
2004-02-20 20:12:44,864 DEBUG net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2047) : attempting to resolve [com.elendal.jFF.model.BoardBean#5]
2004-02-20 20:12:44,868 DEBUG net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2063) : resolved object in session cache [com.elendal.jFF.model.BoardBean#5]
2004-02-20 20:12:44,871 DEBUG net.sf.hibernate.loader.Loader.doQuery(Loader.java:226) : done processing result set (1 rows)
2004-02-20 20:12:44,874 DEBUG net.sf.hibernate.impl.BatcherImpl.logClosePreparedStatement(BatcherImpl.java:203) : done closing: 0 open PreparedStatements, 0 open ResultSets
2004-02-20 20:12:44,877 DEBUG net.sf.hibernate.impl.BatcherImpl.closePreparedStatement(BatcherImpl.java:261) : closing statement
2004-02-20 20:12:44,880 DEBUG net.sf.hibernate.loader.Loader.doQuery(Loader.java:239) : total objects hydrated: 1
2004-02-20 20:12:44,884 DEBUG net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:2166) : resolving associations for [com.elendal.jFF.model.BoardBea
n#5]
2004-02-20 20:12:44,886 DEBUG net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1950) : loading [com.elendal.jFF.model.CategoryBean#4]
2004-02-20 20:12:44,888 DEBUG net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2047) : attempting to resolve [com.elendal.jFF.model.CategoryBean#4]
2004-02-20 20:12:44,889 DEBUG net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2063) : resolved object in session cache [com.elendal.jFF.model.CategoryBean
#4]
2004-02-20 20:12:44,894 DEBUG net.sf.hibernate.impl.SessionImpl.getCollection(SessionImpl.java:3891) : creating collection wrapper:[com.elendal.jFF.model.BoardBean.
threads#5]
2004-02-20 20:12:44,896 DEBUG net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:2182) : calling onLoad()
2004-02-20 20:12:44,898 DEBUG net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:2190) : done materializing entity [com.elendal.jFF.model.BoardBean
#5]
2004-02-20 20:12:44,900 DEBUG net.sf.hibernate.impl.SessionImpl.endLoadingCollections(SessionImpl.java:3043) : 1 collections were found in result set
2004-02-20 20:12:44,902 DEBUG net.sf.hibernate.impl.SessionImpl.endLoadingCollections(SessionImpl.java:3061) : collection fully initialized: [com.elendal.jFF.model.
CategoryBean.boards#4]
2004-02-20 20:12:44,903 DEBUG net.sf.hibernate.impl.SessionImpl.endLoadingCollections(SessionImpl.java:3064) : 1 collections initialized
2004-02-20 20:12:44,918 DEBUG net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:3227) : collection initialized
2004-02-20 20:12:44,921 INFO
com.elendal.jFF.servlets.IndexServlet.service(IndexServlet.java:68) : 0
2004-02-20 20:12:44,923 DEBUG net.sf.hibernate.impl.SessionImpl.close(SessionImpl.java:549) : closing session
2004-02-20 20:12:44,926 DEBUG net.sf.hibernate.impl.SessionImpl.disconnect(SessionImpl.java:3294) : disconnecting session
2004-02-20 20:12:44,928 DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider.closeConnection(DriverManagerConnectionProvider.java:114) : returning connection to pool, pool size: 1
2004-02-20 20:12:44,931 DEBUG net.sf.hibernate.impl.SessionImpl.afterTransactionCompletion(SessionImpl.java:561): transaction completion



My question is who category.id is 0 and not 5?

And why this query selects same information 2 times? (probably because it is bi-directional...)
select boards0_.id as id__, boards0_.cat_id as cat_id__, boards0_.id
as id0_, boards0_.num_threads as num_thre2_0_, boards0_.title as title0_, boards0_.description as descript4_0_, boards0_.cat_id as cat_id0_ from board boards0_ where boards0_.c
at_id=?

_________________
When nothing can possibly go wrong, it will.


Top
 Profile  
 
 Post subject: Re: Incorrect id
PostPosted: Sat Feb 21, 2004 9:22 pm 
Newbie

Joined: Fri Feb 20, 2004 9:03 pm
Posts: 5
Location: Montreal, QC
Ok i found the problem.
Before:
<id column="board_id" type="int">
<generator class="native"/>
</id>
And after:
<id name="board_id" type="int">
<generator class="native"/>
</id>

Hibernate rules ;-)

_________________
When nothing can possibly go wrong, it will.


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.