This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Hibernate Issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Issue " Watch "Hibernate Issue " New topic
Author

Hibernate Issue

Mike Boota
Ranch Hand

Joined: Jul 18, 2002
Posts: 82
Hi,

I have an application that's been running for over a year now. I am using jaxb/hibernate. Recently I am running into an issue where Hibernate is not saving the data to the tables. The data does exists as I do see it in the logs but somehow hibernate is not able to save it. Most of the time it saves but once in a while it does not save and I don't get any errors or exceptions. Anyone experienced this before and knows what might be wrong. How to debug this as I don't get any errors or exceptions. There's nothing changed in the application.

Thanks


MB<br />Sun Certified Programmer for Java2 Platform
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

I don't think Hibernate is guilty.
Does your database support huge counts of records (or even a heavy load) ?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

"There's nothing changed in the application."

What about the database, its location, IP address, anything. Something must have changed.

Maybe the network is having issues.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mike Boota
Ranch Hand

Joined: Jul 18, 2002
Posts: 82
Hi,

Yes we have an Oracle database and it does support huge counts of records plus there is no issue with the load either. It's been working fine at peak times. I tested this off peak hours too and I sometimes get those errors. So really don't where exactly is this error happening and hiberante succeeds but no data loaded and no errors either.

Thanks
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

Is hibernate issuing SQL to the database to store the objects? You have logging on?
Mike Boota
Ranch Hand

Joined: Jul 18, 2002
Posts: 82
Hi,

This is the snippet of the code where a save is done:



I am using jaxb and data is loaded in java objects from xml. payLoadData is the root class. Before saving I did checked if the root class does contain data and the data does exists. But some how hibernated never saves it to the database. I tried the same file several times and most of the times it works but sometimes it just does not insert any data. That's why I am little confused on what exactly is wrong. Thanks for any help.
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

do you have sql debugging enabled on hibernate so you can see the sql commands hibernate is issuing to the database?
Mike Boota
Ranch Hand

Joined: Jul 18, 2002
Posts: 82
Hi,

I enabled the sql debugging too but don't see anything unusual it's that hibernate commits everything fine but never see the data in the database. I again tested it multiple times with the same data and once a while it just does not save the data. Any ideas what else I can look at. Am using Oracle DB for back-end storage.

Thanks
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

Originally posted by Mike Boota:
Hi,

I enabled the sql debugging too but don't see anything unusual it's that hibernate commits everything fine but never see the data in the database. I again tested it multiple times with the same data and once a while it just does not save the data. Any ideas what else I can look at. Am using Oracle DB for back-end storage.

Thanks


I can not tell from your vague statement if hibernate is in fact issuing SQL commands to your database to store your data, or not!?

I assume you see the log entries for the save call, but I need to know if Hibernate has decided that the data needs to be saved and does so, or if Hibernate has decided this object is not changed and does not require an update. Or maybe you have no persistence by reachability or something else is happening.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Are you calls going through EJBs or something else that would create a Transaction, outside the Hibernate scope, that Hibernate is joining that transaction, and that after saving, something goes wrong in that outside transaction, and that transaction is rolled back, causing Hibernate to also rollback?

Mark
Mike Boota
Ranch Hand

Joined: Jul 18, 2002
Posts: 82
Hi,

Here is what' happening. It's a Web Service where I am using hibernate to save the data. A client of the Web Service may send same data over. Now how do I make sure hibernate does save it even if the data is coming over again.

The first step is it validates the data, then it stores the payload in different tables and that's where it's not working (some times it works sometimes it basically does not save and no errors either at save time), then finally it stores the whole payload i.e. xml in one table as a clob and this always works fine, and finally Web Service returns the response to the client.

I never do an update it's always an insert. There is not transaction or ejb's involved it's a straight Web Service. I'll try to debug more but right now am kind of stuck and don't know what else I can look at.

Thanks for the help.
Mike Boota
Ranch Hand

Joined: Jul 18, 2002
Posts: 82
Hi,

I am using Don't know if changing it to what will be the effect. Also what if I use merge instead of save when trying to persist the object.

Is there any difference between using cascade=none|save-update and using merge instead of save. Just trying to see what other options I have as I right now I am stuck and really can't figure out what's going on.

Here is the current code snippet where I am saving the object to the databse:



It randomnly does not save the data, I even tried the same file over and over. Any help is appreciated.

Thanks.
[ March 06, 2007: Message edited by: Mike Boota ]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Cascade options and merge aren't the same thing.

Cascade options are in regard to what Hibernate should do with related objects. So if I have a relationship between a and b, a has an instance of b. In the mapping for a, there is a relation mapping to b, in that mapping the Cascade option of none would mean when I do save(a) nothing is done with the b it holds. Even if b is changed, new or anything.

Merge is for detached objects and reattaching them to be managed by the Session.

So at this point, can you post your hibernate.cfg.xml (hide your username/password), you mapping hbm.xml files (Or classes with Annotations) and your HibernateUtil class code.

Thanks

Mark
Mike Boota
Ranch Hand

Joined: Jul 18, 2002
Posts: 82
Following are the hbm, hibernate.cfg.xml , and Util Class code. Notification is the root class.





Thanks
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Wow, lots of stuff.

Is it

session.save(notification);

or session.save(data);

that is your code. In one post I see "data" and in the last one I see "notification". probably not the issue, but confusing to me.

I don't see anything in your mapping that looks weird, but there is lots to it. Your HibernateUtil is a bit older ways of doing things, as you can now call getCurrentSession from the SessionFactory, but you might be using Hibernate 2.x instead.

Anyone else see anything to help Mike out?

Mark
 
GeeCON Prague 2014
 
subject: Hibernate Issue