- 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/
我在项目的不同领域遇到了以下异常。最糟糕的是我不知道它是什么......我的项目中没有 com.b.a.c.b 包。我尝试在网络上搜索,但仍然不明白是什么导致了此异常。 在从另一个 Activity
当我尝试单独运行 junit 测试时,出现此错误。当我尝试使用 Ant(它运行所有测试)运行它时,它运行良好。谁能告诉我可能的原因是什么? src 文件夹和 test 文件夹在同一层次结构中。我必须链
考虑以下类: sealed class Fruit(val id: String, val label: String) { object orange : Fruit("Citrus sinen
编译良好: static final Screen screen = Screen.getInstance(); static final InputListener listener = Input
我正在尝试读取 jar 包中的文件 (blip3.out)。我正在使用 getResourceAsStream 获取 url,然后尝试从中读取。我已经进行了多次尝试,并使用其他帖子中的解决方案,但仍然
我将一个项目导入到 eclipse 中并添加了依赖项(仅 oracle 驱动程序和 junit4)。但是当我尝试运行该项目时,我收到 ExceptionInInitializerError 。由于某种
当我尝试运行以下代码时,我收到 ExceptionInInitializerError 而不是空指针异常。为什么? static { String s= null; System.out.
我正在尝试使用 Class.forName 从我的对象调用方法,但出现 java.lang.ExceptionInInitializerError class MainClass(implicit v
我收到了ExceptionInInitializerError。我被告知“getException() 方法现在被称为原因,并且可以通过 Throwable.getCause() 方法以及前面提到的“
我是 Applet 编程新手,想要制作一个 Applet 放在网站上。那么我们开始吧。 这个项目的目标是,如果您单击该按钮,它将在浏览器顶部打开一个 JFrame。但在测试时,它给了我一个 java.
我使用 swing JFrame 作为我的应用程序的 MainFrame。我有一个按钮应该创建一个新窗口。但它会在初始化时崩溃,我不知道为什么。 public class Dialog { p
下面是我在运行服务器时从 netbeans IDE 得到的错误。正如错误所说 Uncompilable source code - Projects.ApplicationMenu is not ab
我正在使用兼容性类来构建用户代理字符串: public abstract class Compatibility { private static int sdkInt = 0; pr
编辑:已解决,但我不明白为什么 在 PokemonEnum 中我有这行 private PokemonEnum[ ] pokemon = PokemonEnum.values(); 我把它改为: pr
我正在尝试初始化 GL11,因为我在引用一个有 的方法时遇到了麻烦 GL11 gl 作为它的参数。我试图在我的渲染器类中初始化它,但它没有用,所以我认为它的初始化搞乱了渲染器并创建了一个新类来初始化。
我在一些论坛上搜索过,这似乎是一个常见问题。但是我找不到解决方案。我没有做任何疯狂的事情,所以发生这种情况似乎很奇怪。 @Override protected Scene onCreateScene(
我一定是在做一些非常愚蠢的事情,但是当我尝试在我的单例中实例化一个对象时,我得到了一个 ExceptionInInitializerError: class MySingleton { priva
请注意,我知道关于的规则 ExceptionInInitializerErrors 它说:任何静态 block 中抛出的异常被包装到ExceptionInInitializerError 然后抛出 E
我在尝试运行我的应用程序时意外遇到了 ExceptionInIntiialize 错误。我相信当用户点击快速聊天按钮时会提示错误。 10-09 18:27:08.450: E/AndroidRunti
当启动 JavaFX 应用程序(嵌入了 Swing 代码)作为 Webstart 时,会发生以下错误: java.lang.ExceptionInInitializerError at com
我是一名优秀的程序员,十分优秀!