Hello,
hibernate-3.2.5
hibernate-annotations-3.3.0
hibernate-commons-annotations-3.3.0
mysql 5.0
tomcat 6.0.14
I have the following model classes, only relevant portions mentioned:
Code:
@Entity
@Table (name="insertion")
public class Insertion extends BaseObject implements AuditableModel {
...
@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.EAGER, optional=false)
@JoinColumn ( name="unit_id", nullable=false)
public Unit getUnit() {
return unit;
}
...
}
@Entity
@Table (name="unit")
public class Unit extends BaseObject implements AuditableModel {
...
@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.EAGER, optional=false)
@JoinColumn ( name="menu_id", nullable=false)
public Menu getMenu() {
return menu;
}
...
}
@Entity
@Table (name="menu")
public class Menu extends BaseObject implements AuditableModel {
..
@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.EAGER)
@JoinColumn ( name="background_content_id")
public Content getBackground() {
return background;
}
...
}
@Entity
@Table (name="content")
public class Content extends BaseObject implements AuditableModel {
...
}
Code:
BaseObject
is
Code:
org.appfuse.model.BaseObject
So, an Insertion has a Unit, which has a Menu which has a background (Content).
So, when an insertion is loaded, it should load its unit, and its menu and the background content.
The issue is, if I access the content in Menu.setBackground() class, the Content object's Id is set, but rest of the member attributes are null.
But if I access the Menu object itself, from Unit class, as in Unit.setMenu(), the Menu class has its Id set, and other attributes also have values. (like Customer, createdDate, etc. etc.)
I did a sql output of the queries that hibernate generates, and one query which is invoked on getUnit() of Insertion is as below:
Code:
select unit0_.id as id11_10_, unit0_.config_id as config4_11_10_, unit0_.created_date as created2_11_10_, unit0_.menu_id as menu5_11_10_, unit0_.updated_date as updated3_11_10_,
config1_.id as id4_0_, config1_.base_offset_x as base2_4_0_, config1_.base_offset_y as base3_4_0_, config1_.click_url_prefix as click4_4_0_, config1_.click_url_suffix as click5_4_0_,
config1_.created_date as created6_4_0_, config1_.customer_id as customer12_4_0_, config1_.offset_x as offset7_4_0_, config1_.offset_y as offset8_4_0_, config1_.open as open4_0_, config1_.open_left_icon_content_id as open13_4_0_,
config1_.open_right_icon_content_id as open14_4_0_, config1_.position as position4_0_, config1_.updated_date as updated11_4_0_,
customer2_.id as id6_1_, customer2_.created_date as created2_6_1_, customer2_.name as name6_1_, customer2_.short_name as short4_6_1_, customer2_.updated_date as updated5_6_1_,
content3_.id as id5_2_, content3_.click_url as click2_5_2_, content3_.click_url_nw as click3_5_2_, content3_.content as content5_2_, content3_.created_date as created5_5_2_, content3_.label as label5_2_,
content3_.offset_x as offset7_5_2_, content3_.offset_y as offset8_5_2_, content3_.parent_menu_id as parent12_5_2_, content3_.sequence_num as sequence9_5_2_, content3_.sub_menu_id as sub13_5_2_,
content3_.type as type5_2_, content3_.updated_date as updated11_5_2_,
content4_.id as id5_3_, content4_.click_url as click2_5_3_, content4_.click_url_nw as click3_5_3_, content4_.content as content5_3_, content4_.created_date as created5_5_3_, content4_.label as label5_3_,
content4_.offset_x as offset7_5_3_, content4_.offset_y as offset8_5_3_, content4_.parent_menu_id as parent12_5_3_, content4_.sequence_num as sequence9_5_3_, content4_.sub_menu_id as sub13_5_3_,
content4_.type as type5_3_, content4_.updated_date as updated11_5_3_,
menu5_.id as id9_4_, menu5_.background_content_id as background8_9_4_, menu5_.created_date as created2_9_4_, menu5_.customer_id as customer7_9_4_, menu5_.description as descript3_9_4_,
menu5_.foreground_content_id as foreground6_9_4_, menu5_.node_type as node4_9_4_, menu5_.updated_date as updated5_9_4_,
content6_.id as id5_5_, content6_.click_url as click2_5_5_, content6_.click_url_nw as click3_5_5_, content6_.content as content5_5_, content6_.created_date as created5_5_5_,
content6_.label as label5_5_, content6_.offset_x as offset7_5_5_, content6_.offset_y as offset8_5_5_, content6_.parent_menu_id as parent12_5_5_, content6_.sequence_num as sequence9_5_5_,
content6_.sub_menu_id as sub13_5_5_, content6_.type as type5_5_, content6_.updated_date as updated11_5_5_,
customer7_.id as id6_6_, customer7_.created_date as created2_6_6_, customer7_.name as name6_6_, customer7_.short_name as short4_6_6_, customer7_.updated_date as updated5_6_6_,
content8_.id as id5_7_, content8_.click_url as click2_5_7_, content8_.click_url_nw as click3_5_7_, content8_.content as content5_7_, content8_.created_date as created5_5_7_, content8_.label as label5_7_,
content8_.offset_x as offset7_5_7_, content8_.offset_y as offset8_5_7_, content8_.parent_menu_id as parent12_5_7_, content8_.sequence_num as sequence9_5_7_, content8_.sub_menu_id as sub13_5_7_,
content8_.type as type5_7_, content8_.updated_date as updated11_5_7_,
styles9_.unit_id as unit1_12_, style10_.id as style2_12_, style10_.id as id10_8_,
style10_.created_date as created2_10_8_, style10_.customer_id as customer6_10_8_, style10_.renderer as renderer10_8_, style10_.updated_date as updated4_10_8_, style10_.url as url10_8_,
customer11_.id as id6_9_, customer11_.created_date as created2_6_9_, customer11_.name as name6_9_, customer11_.short_name as short4_6_9_, customer11_.updated_date as updated5_6_9_
from unit unit0_ inner join config config1_ on unit0_.config_id=config1_.id
left outer join customer customer2_ on config1_.customer_id=customer2_.id
left outer join content content3_ on config1_.open_left_icon_content_id=content3_.id
left outer join content content4_ on config1_.open_right_icon_content_id=content4_.id
inner join menu menu5_ on unit0_.menu_id=menu5_.id
left outer join content content6_ on menu5_.background_content_id=content6_.id
left outer join customer customer7_ on menu5_.customer_id=customer7_.id
left outer join content content8_ on menu5_.foreground_content_id=content8_.id
left outer join unit_style styles9_ on unit0_.id=styles9_.unit_id
left outer join style style10_ on styles9_.style_id=style10_.id
left outer join customer customer11_ on style10_.customer_id=customer11_.id
where unit0_.id='someId'
and when I run this query, I do see that content6_ has all its values present (
Code:
content6_
is joined with
Code:
menu5_.background_content_id=content6_.id
)
So, this shows that the query is returning proper values for the background (Content) object, but the object supplied to
Code:
Menu.setBackground()
only has its id set.
But when I access
Code:
background.getType()
in
Code:
Menu.setBackground(Content background)
, I get the value as null.
I did find some threads on this forum addressing 'similar' issues, but I did not fully get a satisfactory answer, why this is happening (proxy object?) and how to resolve this (??).
Any direction in this regard will be helpful.
Thanks
MRather