I am using GWT with JPA and Hibernate in Tomcat Apache container. When I try testing my dao and database connection from a Standalone java application it works fine. Howerver, when I use it in server enviornment, it SOMETIMES works sometimes doesn't. Here is an abridged sequence of logevents:
org.hibernate.type.BasicTypeRegistry - Adding type registration boolean -> org.hibernate.type.BooleanType@82b436 INFO org.hibernate.cfg.Environment - Hibernate 3.6.0.Final 42937 [btpool0-0] INFO org.hibernate.cfg.Environment -hibernate.properties not found 42940 [btpool0-0] INFO org.hibernate.cfg.Environment -Bytecode provider name : javassist [btpool0-0] INFO org.hibernate.cfg.Environment - usingJDK 1.4 java.sql.Timestamp handling 43038 [btpool0-0] DEBUG org.hibernate.id.factory.DefaultIdentifierGeneratorFactor - Regis开发者_开发知识库tering IdentifierGenerator strategy [uuid2] -> [class org.hibernate.id.UUIDGenerator] 43069 [btpool0-0] INFO org.hibernate.ejb.Version - Hibernate EntityManager 3.6.0.Final
43090 [btpool0-0] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration text -> org.hibernate.type.TextType@1cf00aa43106 [btpool0-0] DEBUG org.hibernate.ejb.Ejb3Configuration - Look up for persistence unit: transactions-optional 43269 [btpool0-0] DEBUG org.hibernate.ejb.Ejb3Configuration Detect class: true; detect hbm: true
43285 [btpool0-0] DEBUG org.hibernate.ejb.packaging.AbstractJarVisitor - Searching mapped entities in jar/par: file://xxxxx 43378
[btpool0-0] DEBUG org.hibernate.ejb.packaging.AbstractJarVisitor - Filtering: com.demo.server.hello 43492 [btpool0-0] DEBUG org.hibernate.ejb.packaging.AbstractJarVisitor - Java element filter matched for com.demo.server.hello 43505
[btpool0-0] DEBUG org.hibernate.ejb.Ejb3Configuration - Detect class: true; detect hbm: true
43505 [btpool0-0] DEBUG org.hibernate.ejb.Ejb3Configuration - Creating Factory: transactions-optional
After this I get no log message and my client layer can not talk to database layer. When my client layer is able to talk to database layer, the entry following above log entry is as follows:
1063 [main] DEBUG org.hibernate.cfg.Configuration - Processing hbm.xml files
If you could point out as to what might be going wrong, I will really appreciate it. I can't figure out if its eclipse compilation fault, or some problem in GWT plugin or (most likely) my programming bug.
Are you sure you are using JPA? I'm not familiar with GWT, but I assume it deploys your application as a WAR file. If so, check if you WAR file contains a META-INF/persistence.xml file, and verify the connection details from there.
1063 [main] DEBUG org.hibernate.cfg.Configuration - Processing hbm.xml files
It seems that Hibernate is creating a session every time your client is able to talk to the database. The fact that sometimes it's called (and works) indicates that it's not a problem with Hibernate. Otherwise, you'd see a consistent behavior. So, I would double-check if the requests are not failing before reaching Hibernate. For instance, I would try to add some debug log entries before and after Hibernate is called.
精彩评论