I got around the session management issue (which from what I've read here and after much googling - is a big deal in Hibernate) - simply by moving the opening/closing of the session, through encapsulation, right down to the servlet level so there is one session per request...which may not be the best way of doing it but after all the fighting I've done w/ this simple example....I'm ready to accept (for now.)
All I was hearing in here in reply was "session management works depending on what you're doing" - which is a non-answer if I've ever heard one...I think most people tend to avoid this question like the plague on these forums...but I hear "Seam" will take care of this issue?
Anyhow, now that I've gotten that far, it is *still* not retrieving the list as I would have expected!! Even though the query shows a left outer join...and when I run it against the data...it works, the Attributes list is null.
I've made slight modifications to my hbm.xml files...here's AttributeCategory and Attribute, respecitvely:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class
name="com.agribeef.bol.AttributeCategory"
proxy="com.agribeef.bol.AttributeCategory"
table="ed_attribute_category">
<id name="ID" column="attribute_category_id" type="int" unsaved-value="0">
<generator class="identity"/>
</id>
<property name="DirectoryID" column="directory_id"/>
<property name="Category" column="category"/>
<list
name="Attributes"
table="ed_attribute"
inverse="true"
lazy="true"
fetch="join"
cascade="save-update">
<key column="attribute_id" />
<index column="attribute_category_id" />
<one-to-many class="com.agribeef.bol.Attribute" />
</list>
</class>
</hibernate-mapping>
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class
name="com.agribeef.bol.Attribute"
proxy="com.agribeef.bol.Attribute"
table="ed_attribute">
<id name="ID" column="attribute_id" type="int" unsaved-value="0">
<generator class="identity"/>
</id>
<property name="CategoryID" column="attribute_category_id"/>
<property name="Name" column="name"/>
<property name="Contents" column="contents"/>
<many-to-one
name="Category"
cascade="save-update"
class="com.agribeef.bol.AttributeCategory"
lazy="false"
fetch="join"
insert="false"
update="false"
column="attribute_category_id" />
</class>
</hibernate-mapping>
...the classes remain the same.
I can pull the AttributeCategory when "querying" it...but obviously I can't go any deeper...the list is Attributes list in AttributeCategory wasn't populated.
Here are the generated queries (formatted for readability):
Code:
select
attributec0_.attribute_category_id as attribute1_,
attributec0_.directory_id as directory2_5_,
attributec0_.category as category5_
from
ed_attribute_category attributec0_
Code:
select
attributes0_.attribute_id as attribute1_2_,
attributes0_.attribute_category_id as attribute2_2_,
attributes0_.attribute_id as attribute1_1_,
attributes0_.attribute_category_id as attribute2_4_1_,
attributes0_.name as name4_1_,
attributes0_.contents as contents4_1_,
attributec1_.attribute_category_id as attribute1_0_,
attributec1_.directory_id as directory2_5_0_,
attributec1_.category as category5_0_
from
ed_attribute attributes0_
left outer join
ed_attribute_category attributec1_
on
attributes0_.attribute_category_id=attributec1_.attribute_category_id
where attributes0_.attribute_id=?
The PK returned in the first query is "1"....so if I run the second query, having replaced the "?" w/ "1"....I get the data I expect!
What am I doing wrong here?
Thanks again!