-->
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: why is my collection not loaded?
PostPosted: Sun Nov 12, 2006 8:26 pm 
Beginner
Beginner

Joined: Tue Feb 08, 2005 1:29 pm
Posts: 20
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: v3

Mapping documents:
<hibernate-mapping package="com.etil.sudetp.business.manager.gameaccount.impl" >
<class name="Account" table="account" >
<cache usage="nonstrict-read-write"/>

<id name="accountId" unsaved-value="null" column="ACCOUNTID" >
<generator class="assigned"/>
</id>
<property name="timestampDB" type="long" column="TIMESTAMP" />
<property name="date" type="java.util.Date" column="DATE" />
<property name="description" type="string" column="DESCRIPTION" />
<property name="gameId" type="int" column="GAMEID" />
<property name="serverId" type="int" column="SERVERID" />
<map name="accountFieldMap" table="ACCOUNTFIELDMAP" cascade="all">
<key column="ACCOUNTID" not-null="true"/>
<map-key column="FIELDID" type="string"/>
<one-to-many class="AccountField"/>
</map>
</class>
</hibernate-mapping>
<hibernate-mapping package="com.etil.sudetp.business.manager.gameaccount.impl" >
<class name="AccountField" table="accountfieldmap" >
<id name="id" type="int" column="ID" >
<generator class="native"/>
</id>
<property name="accountId" type="string" column="ACCOUNTID" />
<property name="fieldId" type="string" column="FIELDID" />
<property name="status" type="string" column="STATUS" />
<property name="value" type="string" column="VALUE" />
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Criteria query = s.session.createCriteria(AccountSale.class).add(
Expression.eq("userId", userId));

List sales = query.list();
for (Iterator it = sales.iterator(); it.hasNext(); ) {
AccountSale sale = (AccountSale) it.next();
Account account = (Account) s.session.get(Account.class, sale.getAccountId());
account.getAccountFieldMap();
sale.setAccount(account);
}

Why aren't my account fields loaded with the account? Worst than that, why is my account even not loaded if I am using the load method rather than the get.

Thanks.
DvJ


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 12, 2006 11:24 pm 
Regular
Regular

Joined: Tue Sep 26, 2006 11:37 am
Posts: 115
Location: Sacramento, CA
Ingenu,

Try playing with the lazy settings for the many-to-one association. You can set lazy to false if you are sure you always want the association or you can play with Hibernate.initialize().

The load() api just generates a proxy, the get() api downloads from the database. The load() is very useful for example when you only know the id of an object and you just need the id in the rest of your code. You call load(), get a proxy object and use it to save the associated object or what else you need to do. If later on in the code you access some other property then the access to the database is generated.

Hibernate has a bit of a learning curve. Please read the manual, you will avoid lots of frustration. Talking from own experience :)

Marius


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.