I have a one to many relationship b/w Company and Activity.
When I load an instance of Activity using its Primary Key(activityId) the company object is also loaded. How can I stop this from happening ?
Info:
hibernate-2.1, Oracle8, query code:
List messages = newSession.find(" from hibernate.CompanyActivity as activity where activity.activityId=327");
The 2 hbm.xml file snippets are ...
1/. Company.hbm.xml
<class
name="hibernate.Company"
table="COMPANY"
>
<id
name="companyId"
type="java.lang.Long"
column="COMPANY_ID"
>
<generator class="assigned" />
</id>
<property
name="name"
type="java.lang.String"
column="NAME"
not-null="true"
length="200"
/>
<!-- bi-directional one-to-many association to Activity -->
<set
name="companyActivity"
lazy="true"
inverse="true"
>
<key>
<column name="COMPANY_ID" />
</key>
<one-to-many
class="hibernate.CompanyActivity"
/>
</set>
2/.
<class
name="hibernate.CompanyActivity"
table="ACTIVITY"
>
<id
name="activityId"
type="java.math.BigDecimal"
column="ACTIVITY_ID"
>
<generator class="sequence">
<param name="sequence">SEQ_PK_ACTIVITY</param>
</generator>
</id>
<!-- bi-directional many-to-one association to Company -->
<many-to-one
name="company"
class="hibernate.AdtCompany"
not-null="true"
outer-join="true"
cascade="none"
>
<column name="COMPANY_ID" />
</many-to-one>
-- I also tried with outer-join="false", and not-null="false".
log4j.properties:
#This is only for hello's test !!!
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
### root logger option ###
log4j.rootLogger=warn, stdout
### Hibernate logging options ###
log4j.logger.net.sf.hibernate=info
### log JDBC bind parameters ###
log4j.logger.net.sf.hibernate.type=debug
### log PreparedStatement cache activity ###
log4j.logger.net.sf.hibernate.ps.PreparedStatementCache=info
In the logs i can see the 2 queries being executed and statements like:
Hibernate: select blah blah....
221:37:29,148 DEBUG BigDecimalType:68 - returning '327' as column: ACTIVITY_1_
1:37:29,228 DEBUG LongType:68 - returning '717' as column: COMPANY_ID
Hibernate: select
Hibernate: select company0_.COMPANY_ID blah blah....
1:37:29,278 DEBUG LongType:46 - binding '717' to parameter: 1
TIA,
Rahul
|