- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我开始学习Hibernate,出现这样的错误:
exception
javax.servlet.ServletException: Servlet execution threw an exception
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.ExceptionInInitializerError
logic.HibernateUtil.<clinit>(HibernateUtil.java:16)
logic.DefaultTableDAO.getItems(DefaultTableDAO.java:38)
servlet.TestServlet.doGet(TestServlet.java:36)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:267)
org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:231)
org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:240)
org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:691)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726)
logic.HibernateUtil.<clinit>(HibernateUtil.java:14)
logic.DefaultTableDAO.getItems(DefaultTableDAO.java:38)
servlet.TestServlet.doGet(TestServlet.java:36)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:100)
org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:54)
org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137)
org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)
org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:257)
org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:231)
org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:240)
org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:691)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726)
logic.HibernateUtil.<clinit>(HibernateUtil.java:14)
logic.DefaultTableDAO.getItems(DefaultTableDAO.java:38)
servlet.TestServlet.doGet(TestServlet.java:36)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
我使用 Tomcate 8.5.6、Java 8、Hibernate 和 postgresql 9.5.2。JDBC 驱动程序 9.4-1201
hibernate .cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:postgresql://localhost:5432/postgres?charSet=LATIN1</property>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.username">postgres</property>
<property name="connection.password">java1235</property>
<property name="connection.pool_size">1</property>
<property name="dialect">org.hibernate.dialect.PostgreSQL9Dialect</property>
<property name="cache.provider_class">org.hibernate.cache.internal.NoCachingRegionFactory</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
hibernate 工具.java
public class HibernateUtil {
private static SessionFactory sessionFactory;
static {
try {
sessionFactory = new Configuration().buildSessionFactory();
} catch (Throwable e){
throw new ExceptionInInitializerError(e);
}
}
private HibernateUtil(){}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
调用Hibernate的类
package servlet;
import logic.DefaultTable;
import logic.DefaultTableDAO;
import logic.Factory;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class TestServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
List<Integer> list = new ArrayList<>();
list.add(1);
list.add(1);
list.add(1);
list.add(1);
list.add(1);
Factory factory = Factory.getInstance();
DefaultTableDAO table = factory.getItemDao();
List<DefaultTable> items = null;
try {
items = table.getItems();
} catch (SQLException e) {
e.printStackTrace();
}
req.setAttribute("listItem", list);
req.setAttribute("str", items.get(0).getPartName());
req.getRequestDispatcher("/WEB-INF/my_page.jsp").forward(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.getWriter().write("NOOOOOOOOOOOOOOOOOO");
}
}
登录 Tomcate
05-Nov-2016 15:44:39.412 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 846 ms
05-Nov-2016 15:44:46.519 INFO [http-nio-80-exec-1] org.hibernate.Version.logVersion HHH000412: Hibernate Core {5.2.4.Final}
05-Nov-2016 15:44:46.522 INFO [http-nio-80-exec-1] org.hibernate.cfg.Environment.<clinit> HHH000206: hibernate.properties not found
05-Nov-2016 15:44:46.524 INFO [http-nio-80-exec-1] org.hibernate.cfg.Environment.buildBytecodeProvider HHH000021: Bytecode provider name : javassist
05-Nov-2016 15:44:46.567 INFO [http-nio-80-exec-1] org.hibernate.annotations.common.reflection.java.JavaReflectionManager.<clinit> HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
05-Nov-2016 15:44:46.730 WARN [http-nio-80-exec-1] org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.initiateService HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections
05-Nov-2016 15:44:46.733 WARN [http-nio-80-exec-1] org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService HHH000342: Could not obtain connection to query metadata : The application must supply JDBC connections
org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
05-Nov-2016 15:46:49.454 INFO [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.core.StandardContext.reload Reloading Context with name [] has started
05-Nov-2016 15:46:49.986 INFO [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.core.StandardContext.reload Reloading Context with name [] is completed
org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
最佳答案
当前的错误是因为你没有正确配置hibernate.dialect
,你可以在你的hibernate.cfg.xml
文件中设置如下:
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
此外,请确保使用正确的属性名称设置其他属性:
hibernate.connection.driver_class = org.postgresql.Driver
hibernate.connection.url = yoururl
hibernate.connection.username = youruserid
hibernate.connection.password = yourpwd
hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
可以引用here
关于java.lang.ExceptionInInitializerError logic.HibernateUtil.<clinit>(HibernateUtil.java :16),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40429591/
我知道 new、dup、invokespecial 和 astore 字节码模式将调用初始化方法 在类实例化期间。什么调用了特殊的 方法,什么时候发生? 我的猜测是 在之前 方法被调用。这是否记
对于特定类,一个方法只执行一次是否正确? 最佳答案 我创建了测试类并按如下方式引用它 新运算符 反射(reflection) block 仅被引用 1 次 public class ClinitTe
我无法理解下面的文字... 是否意味着 是为空的构造函数?为什么拥有两个不同的版本很重要? https://docs.oracle.com/javase/specs/jvms/se7/html/jvm
当我看到 JVM 规范时,它说每个类最多有一个类初始化方法,那就是“clinit”,所以我认为我们应该有一些命令来查看该方法是如何在 .class 文件中编码的。 一开始我以为用javap就可以了,但
我正在使用 iCal4J 向 MS Outlook 发送约会,效果很好,约会正在进行中。但是我的控制台显示以下内容: Oct 24, 2013 9:53:57 AM net.fortuna.ical4
这是我的测试助手: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpa
我开始学习Hibernate,出现这样的错误: exception javax.servlet.ServletException: Servlet execution threw an excepti
我是android游戏开发人员的新手,但经过几个月的工作,我终于在ue4中完成了游戏的制作。 但是,当将其上传到Google Play的Alpha轨道上,然后尝试启动该应用程序时,它会崩溃。 错误本身
最近我们在 AS 3.0.1 中注意到了这些警告: Error:WARNING in butterknife.Unbinder.:()V: defining a static interface me
我正在创建一个应用程序,但出现如下所示的错误。 我正在使用 Tomcat 6.0 和 Spring 3.0。 SEVERE: Servlet.service() for servlet jsp thr
我正在使用 Httpclient-4.5.2.jar 和 httpcore-4.4.4.jar HttpClient 组件,但出现以下错误。 Exception in thread "main" ja
我的请求URL中有字符[和],项目部署在Tomcat8.5.33上。当我发布请求时发生了一些异常。 20-Sep-2018 10:55:36.494 WARNING [http-nio-8075-ex
我成功使用了我编写的 Java 命令行程序使用 Apache POI 文件读取 MicrosoftWord (.docx) 文件并邮寄。我希望将其打包为可执行 jar。 我正在创建这个通过获取我的应用
我是一名优秀的程序员,十分优秀!