This week's giveaway is in the Programmer Certification (OCPJP) forum.
We're giving away four copies of Java Mock Exams (software) and have David Mayer on-line!
See this thread for details.
Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Hibernate fetch="join"

 
Kim Lilienfeld
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!