I've got a problem when trying to insert a record into my database. The insert itself seems to work fine (no warnings/errors) in the console logs when I run the below code, and I can even see where hibernate has generated my new Track_ID number (for index column in db). However when I check the actual db once the insert has allegedly been flushed and committed the new row does not appear there???
If I manually insert a row to the db and then use hibernate to select it out of db, it all works fine and i get the object returned.
Below is initial stuff that I hope will let someone solve my problem, if there 's something else somebody wants to see, let me know and I'll add to the post.
Any help on this one greatly appreciated as it's driving me up the wall!!!
Java code (simple main method containing the following) to do the actual insert (called from an ant task running under eclipse) :-
The log output that comes out of running above (anything with "*****" are my system.out debug statements, see code above. the reason it generates track id 101 is because I manually inserted a record id of 100 to make sure that code was generating correct id's) :-
My hibernate.properties file (located at root of src directory and copied over to output src dir when ant does the prepare task for the project) :-
[ March 17, 2008: Message edited by: steve jones ]
[ March 17, 2008: Message edited by: steve jones ] [ March 17, 2008: Message edited by: steve jones ]
Um, where is your Connection Pool? Hibernate requires a Connection Pool, either using a third party Connection Pool like C3PO, which comes with Hibenate, or a Datasource through a container like an App Server.
Joined: Mar 16, 2008
Hi Mark, Thanks for replying. I've added the code tags and a bit of indenting to the code itself, hope it's readable now.
Mapping, java object and config files given below. I don't think it's anything to do with connection pooling as the other tests which pull data out of the database seem to work fine (see below points for bit more info). I'm only using it in the simplest way ie. 1 ant target launching just one main thread which is exactly as you see in the code above.
I've also looked at a number of websites/books and they all seem to run a similar example in almost exactly the same kind of configuration with no mention of specifying connection pools anywhere (but I did notice they tended to use an xml config file whereas I'm using the hibernate.properties file (shown at bottom of original post), but it should do same thing as far as I'm aware?).
Here's a couple more things I've tried since posting :-
* used the wasCommitted() method of the session to check what it reports and getting 'true' value back which would indicate the inserts have been committed but again checking the db later shows no row inserted.
* Manually added a row to db for testing. If i use hibernate to load the manually inputted row it successfully pulls it back and I get the expected Track object
* Tried changing the flush method on the session to ALWAYS via calling but as with everything else it makes no difference.
Could it be something to do with some setting for HSQL that I haven't setup correctly?
Here's my Track.hbm.xml file :-
Here's my Track.java class :-
Here's the ddl that's in the music.script file of the HSQL data directory :-
where the 'STODGE' track above is the one I manually added to the db.
Hi Jaikiran, Thanks for the suggestion, I dropped the table and recreated it with the ddl you gave. Again the logs were almost identical to the one I've posted (ie. it told me it had committed the stuff successfully) but again checking after the process had ran I have an empty table!!!
Anything else you/someone might suggest? For a bit more info. on what I'm trying to do, this is basically the first part of chapter 3 of the book "Hibernate , A developers notebook" by James Elliott, but updated code/config bits for hibernate 3 (Note I've followed most of the details of updating as given by the following site : http://www.epischel.de/wordpress/?p=24 )
Maybe I should just give up with HSQL and write it off as not very good (blatant flame to hsql devotees so they maybe inspired to help me out and point out where it's me and not hsql that's a write off ). Can anyone recommend a good free rdbms that's simple to install and use? I tried setting up postgresql earlier but eventually gave up as stuffing around with all the configuration was proving just as much of a headache as this problem.
Originally posted by steve jones: Can anyone recommend a good free rdbms that's simple to install and use? I tried setting up postgresql earlier but eventually gave up as stuffing around with all the configuration was proving just as much of a headache as this problem.
For simple application like this, i personally use MySQL which is simple to install and use.
When posting any logs or console displays, please please add carriage returns, so that we can read the thread. You can always go back and edit your posts to add them.
Joined: Mar 16, 2008
Hi guys, Mark : Not sure what browser you're viewing this thread with but I've viewed it with both firefox and internet explorer and the log entry has carriage returns and appears totally readable when I look at it in either (but just to help I'll re-post the bits that I think matter below).
Jaikiran : Good idea but as far as I know mysql isn't free so unfortunately doesn't solve my problem.
Log highlights, this is taken from the part following it successfully setting up a connection to the db and now its trying to create the session factory :-
I am using FF 220.127.116.11 and I have to scroll quite a bit to the right to get to any text in the posts.
Sorry, I am not being much help, but I just can't read the posts.
Joined: Mar 16, 2008
hmmmmmmmmmmmmmmmmm............. I appear to have solved the problem, but how I solved it doesn't make much sense!!
While trying to view the logs from the database while the transaction was in progress I threw in a Thread.sleep(20*1000) just after the tx.commit() statement and for some reason this caused the transaction to be permanently committed to the db!
I've played around with the delay I need to use and for some reason it has to be no less than 19 seconds or the transaction doesn't seem to get committed.
So now my question has changed to :- Anybody have any idea why this delay seems to work???
Mark is right. Even i am having problem reading this thread (i'm using Firefox 2.0.0). If you could edit your post to delete a couple of lines before and after (including) the following statement in the log
01:28:41,560 DEBUG SessionFactoryImpl:177......
that would be great.
Coming back to what you mention about HSQLDB behaviour, i hadn't heard about such a thing before. But after you mentioned the 20 second delay, i read the HSQLDB docs and found the WRITE_DELAY property of the server (which i think in your case is set to true). Try setting it to FALSE and see if it helps. Read through that doc to understand what that property is meant for.
Joined: Mar 16, 2008
Hi Jakiran/Mark, Looks like Jakiran found the solution! It was indeed the default setting of the WRITE_DELAY setting of HSQL db that was causing the problem, it's set at 20 seconds. Turning the WRITE_DELAY function off in the db sorted the problem.
Because I'm running the db in a mode which means its only ever up when I run my application code, the db was never alive for more than 20 seconds thus the committed additions were never committed to file.
Thanks for all your help and apologies for the awkward formatting of the thread.