-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Lazy Loading
PostPosted: Tue Nov 28, 2006 8:32 am 
Beginner
Beginner

Joined: Wed Nov 22, 2006 5:59 am
Posts: 29
Location: London
I have a problem with lazy loading. I am using a database model in which I have a Journal table which contains details of events which which have happened to other tables in the database e.g if a new entry is added to a table a journal entry is created. The problem is when I select data from the database I don't always want all the journals which relate to that object or any objects it has joined so I am using lazy loading so they are only loaded on demand. The problem is that if I want to add a journal entry to the object I am using by adding it to its Journals collection Nhibernate tries to fetch all the journals which relate to that object. This causes an Exception to be thrown as there is no open session. Is there a way to set up NHibernate so that I can add Journal entries without selecting all of them first?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 9:29 am 
Beginner
Beginner

Joined: Tue Nov 21, 2006 5:18 am
Posts: 31
Location: Bangalore, India
Hi,

The main thing about lazy loading is depends on the primary key of the particular mapping. If you dont have id of that journal it will throw exception.
Its depends on the id of journal table, so you should not close your session before lazy load call.

For more you can put your joins, I can help you

_________________
persist_coder
--credit please if it helps you


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 9:46 am 
Beginner
Beginner

Joined: Wed Nov 22, 2006 5:59 am
Posts: 29
Location: London
The problem is I don't want to load all the Journal objects I just want to add a new Journal object to the object I am currently using so that this gets persisted to the database when I save the object. E.g I have a Message object and when a new Message is created a Journal object is created with info about the message etc. I want to be able to add this Journal object to my message object so that when I save or update the message the Journal object is also added to the database, without having to load all the Journals which refer to that object.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 9:53 am 
Beginner
Beginner

Joined: Tue Nov 21, 2006 5:18 am
Posts: 31
Location: Bangalore, India
Hi,

If you could post your mapping file, and java source for saving into db,

I may be able to help you.

_________________
persist_coder
--credit please if it helps you


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 11:04 am 
Beginner
Beginner

Joined: Wed Nov 22, 2006 5:59 am
Posts: 29
Location: London
I have managed to sort the problem by saving the Journal in a different way. Thanks for your help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.