我正在Glassfish 4.1.1捆绑Netbeans服务器上部署我的REST项目。作为maven依赖,我已经包含了一个已经完成并经过测试的外部netbeans项目,它使用Hibernate来提供功能。所以我应该在我的REST Web服务项目中使用这个Java库项目。
当我调试我的REST项目时,一旦在调试模式下部署并启动Glassfish,REST服务就会被很好地调用,并且一切都很顺利,直到需要调用任何使用Hibernate的方法(来自外部lib项目)。然后崩溃,如下图所示。
在Glassfish服务器启动时,我注意到这两个警告:
Warning: The web application [unknown] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Warning: The web application [unknown] registered the JDBC driver [com.mysql.fabric.jdbc.FabricMySQLDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Information: HV000001: Hibernate Validator 5.1.2.Final
最后,当调用任何Hibernate involucred语句时,浏览器显示的错误是:
exception
javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: java.lang.NoSuchMethodError: org.hibernate.internal.CoreMessageLogger.debugf(Ljava/lang/String;I)V
root cause
org.glassfish.jersey.server.ContainerException: java.lang.NoSuchMethodError: org.hibernate.internal.CoreMessageLogger.debugf(Ljava/lang/String;I)V
root cause
java.lang.NoSuchMethodError: org.hibernate.internal.CoreMessageLogger.debugf(Ljava/lang/String;I)V
我添加了截图:
谢谢你, 学家
-----------编辑具有特定线路的CRASHES ------------
public static void openSession(){
try{
if (!init){
//First inicialization. Force execute static block.
Class.forName(SessionFactory.class.getCanonicalName());
init = true;
}
currentSession = SessionFactory.sessionFactory.getCurrentSession();
currentSession.beginTransaction();
它崩溃在Class.forName(SessionFactory.class.getCanonicalName())。我调用此方法以强制类SessionFactory执行其静态块方法,该方法仅配置Hibernate一次。 使用建议的解决方案将hibernate librery降级到4.xx,它似乎工作,但我不得不改变一些较新的方法来调整我的代码到这个版本(本机查询是不同的,配置中的类元数据不存在... )。此外,当我需要为咨询创建新的基本Hibernate对象时,我遇到了新问题,如Query:
public static User getUserById(Long id) {
try {
String query = "SELECT u FROM User u WHERE u.id = " + id;
Query sentence;
崩溃为:
此外,我在开始时也有同样的警告:
Warning: The web application [unknown] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Warning: The web application [unknown] registered the JDBC driver [com.mysql.fabric.jdbc.FabricMySQLDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Information: HV000001: Hibernate Validator 5.1.2.Final