IntelliJ Java IDE
The moose likes Object Relational Mapping and the fly likes Hibernate fetch= Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "Hibernate fetch="join"" Watch "Hibernate fetch="join"" New topic
Author

Hibernate fetch="join"

Kim Lilienfeld
Greenhorn

Joined: Apr 13, 2004
Posts: 25
Hi

Due to performance reasons when mapping a 1-M relationship I needed the set of objects to be populated from one sql statement straight away. I set lazy="false" and the set was populated immediately *BUT* using multiple SQL statements. After reading through the reference guide and a general google I was pretty sure fetch="join" was all I needed. However, when I set this I got a HibernateMappingException.

I have worked around it by doing the following..
In my mapping:


On my Criteria object .setFetchMode("batchRequests", FetchMode.JOIN)

It is quite an irritating workaround. What am I doing wrong that I can't set this fetchmode in my hbm.xml


As I thought it should be:


The error is:
org.hibernate.MappingException: Error reading resource: XXX.hbm.xml
...
Caused by: org.xml.sax.SAXParseException: Attribute "fetch" must be declared for element type "set".

What must I use for set instead then?? I haven't found the reference guide to be very helpful! I really don't want to set the FetchMode each time. So please let me know if you knwo how I can sort this out.

Thanks!!
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
can you post your full mapping ? sounds like something is wrong with the DTD you are using ???
according to the DTD the fetch attribute is valid for the set element:
http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd (search for "ELEMENT set")


pascal
 
 
subject: Hibernate fetch="join"
 
Threads others viewed
restrict queries in association while fetching data....
Hibernate problem - creating duplicate foreign key index
Hibernate generating queries with duplicate columns
Hibernate - Force foreign key lookup on insert
Hibernate: Found Shared References to a Collection
IntelliJ Java IDE