Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Strange: Lazy OneToOne with same table??

Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I've got two classes/entities for a single table:

@Table (name="template")
public class Template {
protected int id;

protected String name;

@OneToOne(fetch=FetchType.LAZY, cascade=CascadeType.PERSIST)
protected TemplateDetails templateDetails;

// plus getters/setters

@Table (name="template")
public class TemplateDetails extends LazyPojo implements Serializable, IsSerializable{
protected int id;

protected String description;

protected Date createDate = new Date();

protected Date lastChangeDate = new Date();

// plus getters/setters

All of this is because I want to load a list of Templates, but in order not to waste memory, load only the ids and names. And later, if I ask for a specific template, load ONLY its TemplateDetails. I guess it's very normal and easy so far. The problem is that hibernate is ignoring the lazy fetching of the TemplateDetails in the Template class, so I'm loading ALL the information for every template in the list. Does anybody know why?? How can I avoid loading TemplateDetails each time I load Template??

Thank you very much. Hope someone can give me a clue.

I have a knack for fixing things like this ... um ... sorry ... here is a consilitory tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic