-->
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.  [ 4 posts ] 
Author Message
 Post subject: Hibernate Architecture Questions
PostPosted: Fri Jan 26, 2007 1:01 pm 
Newbie

Joined: Fri Jan 26, 2007 9:58 am
Posts: 18
Location: Dublin
Hi All,

Investigating using Hibernate3 for new project, but whilst I'm quite happy with the gerenal development the TDA has raised a few questions that have me a bit stumpted. Points will be awarded for answers ;)

Question 1... (think the answer must be no but would welcome any input ;)

Can Hibernate be statically analysed to determine what SQL will be generated for the queries, inserts etc?

I'm assuming that the answer to this will be detailed unit tests with the SQL logs activated and sent to a separate file?

Question 2...

We're already using plain JDBC/DAO etc., for an existing application, some of these objects will be shared (using xdoclet annotations) to persist them in the new application. The TDA is concerned that (must have read it in a book somewhere) that there will be a high(!) risk of database locking if the two applications don't save to the tables in the same order. Is this likely and is if so is it fixable? I guess we can control this to some extent?

Question 3....

Imagine a title combo box for a new user, titles stored in a look up table (id, desc), separate to the user table. If we create the user in a form bean (struts say) and record the pk of the title. For retrieval of a user in future having the title description would be useful. So we'd map it as an association. To save the original user would we have to retrieve title by pk first or can we create an empty title class and just populate the pk?

Finally I've heard it is posisble with hibernate 3 to update and query using one object across multiple tables? I've found information on doing this for query but not for update. Is this possible?

Many thanks for any info,

Chris.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 26, 2007 4:24 pm 
Newbie

Joined: Mon Aug 15, 2005 10:02 am
Posts: 7
Hi,

Question 1:
Yes you can see(or reproduce) the SQL, with parameters, etc, that will be generated with the API. See this thread http://forum.hibernate.org/viewtopic.php?t=965749

Question 2:
Didn't get the shared object with xdoclet thing but never had problems with more than one application accessing the database (of course requires transaction, locking, short-live sessions, etc)

Question 3:
Yes.

Question 4:
Need to verify.

Reguards.
EugĂȘnio.


Top
 Profile  
 
 Post subject: Re: Hibernate Architecture Questions
PostPosted: Fri Jan 26, 2007 4:28 pm 
Regular
Regular

Joined: Wed Dec 07, 2005 4:19 pm
Posts: 53
chris24m wrote:
Investigating using Hibernate3 for new project, but whilst I'm quite happy with the gerenal development the TDA has raised a few questions that have me a bit stumpted.

First and foremost, make really, really sure that you understand that Hibernate is quite a bit different animal. Understanding the fact that Hibernate is NOT a 'yet another way of JDBC access', but rather an OBJECT PERSISTENCY machine is really important.


Quote:
Can Hibernate be statically analysed to determine what SQL will be generated for the queries, inserts etc?

Statically? No (though, I wish it had an 'explain' and 'why' mode :-). At runtime, you can turn on the SQL query output, so that you can see what Hibernate decided to do. Writing (and running) unit tests with Hibernate really pays off.
But, you will probably worry more about the consequences of statement above than the individual querries. Of course, once you see what Hibernate does, you will be able to to 'tune' it -- using left join fetches etc.

Quote:
We're already using plain JDBC/DAO etc., for an existing application, some of these objects will be shared (using xdoclet annotations) to persist them in the new application. The TDA is concerned that (must have read it in a book somewhere) that there will be a high(!) risk of database locking if the two applications don't save to the tables in the same order. Is this likely and is if so is it fixable? I guess we can control this to some extent?

The main thing you will have to do is handling the deadlocks (recovery pain seems even harder with Hibernate). The save 'order' can be to some degree defined by your object hierarchy mapping (flush appears to travese that mapping - but I am not sure it's 'guaranteed').

Probably, very important will be how you use Sessions (short, long, shared...), because Hibernate transaction commits all the Session changes; if you throw also kitchen and sink into one Session, you may be in for a surprize).
Not to mention that (if you end up using detached objects, such as in case of detach from a session invalidated by a deadlock), you may end up redesigning your exisiting objects -- see the 'identity' woes, the Set<> issues etc.

Quote:
Imagine a title combo box for a new user, titles stored in a look up table (id, desc), separate to the user table. If we create the user in a form bean (struts say) and record the pk of the title. For retrieval of a user in future having the title description would be useful. So we'd map it as an association. To save the original user would we have to retrieve title by pk first or can we create an empty title class and just populate the pk?

In the above case, if I read you right, you may start with a null 'title' to begin with. And learn about using the lazy loading (feches). Often a blessing, sometimes a curse you have to fight.

Quote:
Finally I've heard it is posisble with hibernate 3 to update and query using one object across multiple tables? I've found information on doing this for query but not for update. Is this possible?

EVERYTHING is possible in Hibernate 3. Well, everything - when you can push whatever Hibernate won't do into a stored procedure :-).
The problem is figuring out how to do each of those every-things. You only have 841 pages to read, and then figure out the details by studying the source code.
But it will be well worth it, "trust me".

Please, don't forget to rate this rambling -- if it helped at all.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 26, 2007 8:21 pm 
Newbie

Joined: Fri Jan 26, 2007 9:58 am
Posts: 18
Location: Dublin
Thanks for the info guys, I'm on holiday for the next week and have the Java Persistance book to read so thanks for pointing me in the right direction ;)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.