Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Strange: Lazy OneToOne with same table??

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

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

@Entity
@Proxy(lazy=false)
@Table (name="template")
public class Template {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="template_id")
protected int id;

protected String name;

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

// plus getters/setters
}

@Entity
@Proxy(lazy=false)
@Table (name="template")
public class TemplateDetails extends LazyPojo implements Serializable, IsSerializable{
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="template_id")
protected int id;

protected String description;

@Column(name="create_date")
protected Date createDate = new Date();

@Column(name="last_change_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.

Antonio
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic