aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate - server startup and few other questions 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 - server startup and few other questions" Watch "Hibernate - server startup and few other questions" New topic
Author

Hibernate - server startup and few other questions

Varun Jassy
Greenhorn

Joined: Jul 26, 2012
Posts: 5
Friends,

We have used JDBC in a lot of projects. Coming to ORM, in my current project Hibernate is used.
I notice following 2 things:

1. It take enormously large amount of time for jboss server to start-up. In the log it keeps on repeating following type of statements:



Is it normal for Hibernate to take large amount of time to bind all relationships at start-up or is there something wrong in our configuration?

Q2 - Sometimes when server starts up and all above statements are being printed, server goes out of memory and crashes. Server starts up much faster and without any problem with JDBC. Is it also normal? Does hibernate need a lot more memory than JDBC? Doesn't that sound like a huge drawback of hibernate as compared to JDBC?

Thanks for your reply in advance.

Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2377
    
  28

Yes, Hibernate does need to load the meta-information from the entities and parse named queries and such. And yes, Hibernate does take some memory on startup. However, both things have never been huge issues for us. Hibernate (actuallyJava in general) will slow to crawl if your process is on the verge of going OOM. How much memory are you giving to JBoss? Probably you need to increase the memory allocation to JBoss and it should solve the problem. Or you need to look at what other things are loaded at startup that might be using memory. It could be that you are loading a lot of objects already, and Hibernate it just the proverbial straw on the camel's back.

Varun Jassy
Greenhorn

Joined: Jul 26, 2012
Posts: 5
Thanks for reply Jayesh.

As I said in my post, server starts up very fast with "no hibernate". We have same app with JDBC and with Hibernate - same features. It takes lot longer to startup with hibernate. And it is all because jboss is printing above hibernate binding statements for long long time in the log. We have about 50 domain objects and relationships are sometimes 2-way.

We are allocating 1.5 gb of memory to jboss in both the cases (hibernate and jdbc).

Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1649
    
    7

What are you using for Logging? Why not just set the threshold higher than info for the stuff you don't want to log.


[How To Ask Questions][Read before you PM me]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

How can you call it "enormously long" when those logs clearly show that six tables were all mapped within one millisecond?
Varun Jassy
Greenhorn

Joined: Jul 26, 2012
Posts: 5
Thanks for reply Bill and Paul.
I understand we can reduce amount of logging but my question is different here. I am trying to find if we have configured something in a wrong way because of which hibernate is in a long process to map bindings, or is hibernate built that way.

Paul, that log is only a fraction of complete log.

From yesterday's log file I can see that hibernate bind thing started at 2012-07-26 12:23:03,891 and ended at 2012-07-26 12:24:05,717, which means more than 60 seconds. What is even more surprising that single binding is repeated several times in log. For e.g. this statement appears 24 times between above time range:



Why would hibernate repeat it 24 times? If object A is associated with 10 other objects, will hibernate do the mapping 10 times for A?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Varun Jassy wrote:What is even more surprising that single binding is repeated several times in log. For e.g. this statement appears 24 times between above time range:



Why would hibernate repeat it 24 times? If object A is associated with 10 other objects, will hibernate do the mapping 10 times for A?


Now that's a good (i.e. more productive) question. And perhaps it's one that could be answered by reviewing the Hibernate configuration?

I just started up my application which uses Hibernate, and I don't see any log entries starting with "Bind entity". So it looks like you're using a feature which I'm unfamiliar with. But anyway I would start by looking at the configuration to see if you see any relationship with what you see in the startup logs.
Varun Jassy
Greenhorn

Joined: Jul 26, 2012
Posts: 5
Thanks Paul for your reply.
I searched for this class com.admin.myproj.domain.ApplicationDisplay in whole project and these are its entries:

Inside itself i.e.




Inside another class as an instance variable:



Inside META-INF/persistence.xml (it may be redundant here since annotations are used above???)



Can you compare with the way you have used hibernate and share your thoughts about where the problem is in our case?
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1649
    
    7

There is nothing wrong with your annotations.

It is fine to declare the classes in persitence.xml just make sure each one is defined only once (no accidental duplicates). However I am confused as to why you define



in the same persistence unit. I would either change the transaction-type to JTA and use the first or leave it at RESOURCE_LOCAL and use the second. I would not define them both,. If you require multiples it is best to set them up in separate persistence units, if you don't require multiples just remove one.
Varun Jassy
Greenhorn

Joined: Jul 26, 2012
Posts: 5
Thanks Bill.

I removed this:



But that did not make any difference.
Also I noticed that I see following lines in log are repeated several times:




I am confused about why it is doing the same thing several times at server start up and how to stop that.
 
 
subject: Hibernate - server startup and few other questions