• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Tripple header

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have three questions that are related, kind of like a Nassi-Schneidermann diagram, if one solution doesn't work then the next path is evaluated.

We have a standalone Hibernate integration in JBoss, i.e. we do the Pojos then the tables by hand, then map everything in a hibernate.cfg.xml. Now we need to switch to the MBean. But now we need hbm.xml files, which we don't have of course. These get generated by the Hibernate Plugin, but from the database, which doesn't match the actual persistance classes we so diligently did by hand.

The questions are:

1) Is Hibernate in the transaction with JBoss if the MBean for the SessionFactory is NOT used? More specifically do you have to use the MBean if you want JBoss to manage the transactions, including closing the session and the connection to the database?
2) If we are NOT using the MBean in JBoss do we have to close the session ourselves?
3) Is there any way to configure the MBean with the hibernate.cfg.xml file rather than the hbm.xml files and the HAR file? We just can't generate the HBM files. No way.

Thanks in advance.

Regards

Michael
 
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
Well, actually the MBean or the Hibernate.jar file, it doesn't matter what you are using in JBoss AS. You still follow the exact same rules in Hibernate no matter the environment, in terms of your configuration and mapping files.

I would first say that having all the actual mapping of classes within your hibernate.cfg.xml is a maintenance nightmare, so to speak, they should always be seperated to make it much easier to handle. Or if you are using Java 5.0 then use Annotations.

As far as code, you should always open your Session, start a transaction, commit or rollback, then close your session. This is the "boilerplate" code that you should have everywhere. Then your whole actual Transaction implementation is completely hidden from your code, and it makes no difference whether you use JTA, Hibernate MBean, JBoss AS, JDBC Transactions, your code always stays the same.

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 will also add this, you have this "no way" policy of "generating" your mapping files. Just know that if you do it now it is so so so much cheaper than the problems you will have later. Also why can't you go into the hibernate.cfg.xml file and copy out one class mapping and paste it into a seperate file?

Mark
 
Michael Couck
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark,

Thanks for the word or reason!

I saw the documentation covering open the session, do your stuff then close it. But I was under the impression that JBoss would do that if the MBean is used?

Could you please verify for me that if we in fact don't use the MBean that JBoss will not handle the session, and that if we do use the MBean that JBoss will handle the transactions in Hibernate, i.e. close the session and if necessary rollback?

The reason is that we are not closing the session anywhere at the moment! The result is that after about 12 hours there is a socket exception, here is the stack trace, long but seemingly obvious what the problem is, namely that MySql is closing the connection after a while because we don't do it ourselves:



In any event I suppose that we will have to go the annotation route and generate the HBM files.

Kind regards

Mike
 
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
The MBean is just there to add Hibernate to JBoss's AS, it will plug in with the JTA Transactions the JBoss will create, but it doesn't know when to close a session for you, or when you might want that. Or if you want to commit or rollback, you always have to do that in your code. It makes you a "Good Citizen" as we call it at JBoss.

So you have this Session open for 12 hours, it has a JDBC COnnection from your connection pool, so therefore no other client can get that JDBC COnnection, so as soon as you run out of Connections in your pool, then no more clients can be added to do work. And, of course, the JDBC Connection will definitely timeout.

Mark
 
Michael Couck
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark,

Thank you very much for the word of reason, much appreciated!

Regards

Michael
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic