• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Hibernate XDoclet Set Refresh

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey I am using the below hibernate XDoclet code to get the TempRequest objects as set.
The problem I am facing is, that if i update the table associated with this set, this set does not get refreshed.

I have used everything like...
session.refresh
session.load etc

It might be refreshing the Object but not the set in the same web appliaction session. If I log out and then log in the set gets refreshed.
what could be the problem ?

/**
* @hibernate.set table="tbl_tmp_request" lazy="true" cascade="all"
* inverse="true" where="(status=0 or status=1)"
* order-by="preference_level,request_type,room_type_id"
* @hibernate.collection-key column="owner_profile_id"
* @hibernate.collection-one-to-many class="com.abc.biz.TempRequest"
*
* @return Set of all Requests for this profile.
*/
public Set getTempRequests() {
return tempRequests;
}
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Prem java",
Welcome to the JavaRanch.

We're a friendly group, but we do require members to have valid display names.

Display names must be two words: your first name, a space, then your last name. Fictitious names are not allowed.

Please edit your profile and correct your display name since accounts with invalid display names get deleted.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK so you are having issues when you are saving, loading, etc in a session. Can you also post that code? Remember, if I have an object that is in a session, and I call saveOrUpdate() it doesn't go to the database at that time until the session is flushed, which can be at time of transaction commit.

But your object references are still have the same values it had before. It you want something else from the database that you want, you will have to query for it.

Mark
 
Prem Kash
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mark Spritzler:
OK so you are having issues when you are saving, loading, etc in a session. Can you also post that code? Remember, if I have an object that is in a session, and I call saveOrUpdate() it doesn't go to the database at that time until the session is flushed, which can be at time of transaction commit.

But your object references are still have the same values it had before. It you want something else from the database that you want, you will have to query for it.

Mark



Hey, Thanks for responding...
The problem is not with saving the object in database but after saving the object in database, the current object doesnt give me the newly inserted database values.
The flow is like this...

1. For Object request I call
getRequest(){ returns Request;}
2. saveRequest()
{
getSession;
session.saveOrUpdate(newrequest);
transaction.commit;
// Request Object is persisted into the database
}
3. getRequest();
Now at the call of this request method I dont get the values that i saved at step 2, though I can see those values in the database or after again logging into the page...

Hope you got my problem...
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there anyway you are sharing a Session, from the first getRequest and the second getRequest, such that in the first call it is storing the data in first level cache, then detached and sent to the client. Then the client returns a new version of it with changes, the update opens a new session and saves, commits, then closes the session.

Then in the second call to getRequest, it gets the same Session object from the first call to getRequest, which has the old version of the data in it's cache and returns that object instead of ever going back to the database.

Are you using second level cache by any chance? (Just so we know what we have)

Mark
 
Prem Kash
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mark Spritzler:
Is there anyway you are sharing a Session, from the first getRequest and the second getRequest, such that in the first call it is storing the data in first level cache, then detached and sent to the client. Then the client returns a new version of it with changes, the update opens a new session and saves, commits, then closes the session.

Then in the second call to getRequest, it gets the same Session object from the first call to getRequest, which has the old version of the data in it's cache and returns that object instead of ever going back to the database.


Are you using second level cache by any chance? (Just so we know what we have)

Mark




I am Using Hibernate Annotation method as I have mentioned into my first query, This I think hibernate is using internally and I am not using any session Explicitly to call the getRequest method.

But Yes I am using Hibernate Session for Inserting the data through SaveOrUpdate, but agian I am not closing this session.

post this saveUpdate I am calling the hibernate annotation method again to get the request.

-----------------------------------
/**
* @hibernate.set table="resort.tbl_request" lazy="false" cascade="none"
* inverse="true" where="(status=0 or status=1)"
* order-by="preference_level,request_type,room_type_id"
* @hibernate.collection-key column="owner_profile_id"
* @hibernate.collection-one-to-many class="com.resortpal.biz.Request"
*
* @return Set of all Requests for this profile.
*/
public Set getRequests() {
return requests;
}


//

public boolean saveOrUpdateReq( Request request) {
//logger.debug("saveOrUpdate request for ownerProfile="+request.getOwnerProfile().getId());
Session session = HibernateUtil.getSession();
HibernateUtil.beginTransaction();
try {
if (! request.isNewlyCreated()){ //auto-populated on insert
request.setModified(DateUtil.timeNow());
}
session.saveOrUpdate(request);
}
session.flush()
transaction.commit();

// Now to get the updated request I am calling the getrequests again, it doesnt give me the updates changes.

HOW to Implement Caching, can it solve this problem?
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually you are using XDoclet, I don't see any hibernate annotations there as postied, not to say the that XDOclet might generate Hibernate Annotations, I can't answer you there, since Annotations are now in Java 5, I threw away using XDoclet ever again.

In your last bit of code, I don't see you closing the session object, calling session.close

instead of

session.flush
transaction.commit

Which in essence in that case a redundancy, just have

transaction.commit (this causes a flush anyway)
session.close

And I really would have had it in a try/catch/finally where the commit is at the end of the code in the try and the session.close in the finally, and a transaction.rollback in the catch.

Mark
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can also suggest to look at the actual generated code by XDoclet and see what is really going on.

Mark
 
reply
    Bookmark Topic Watch Topic
  • New Topic