problem :I am trying to configure hibernate orm mapping tool to my java class and using PostgreSQL as my database and configured the password as "password". I'm trying to hibernate orm Mapping tool configuration to my java Class and use PostgreSQL As my database and configure the password to “ password ”. When I tried to run the application, I have encountered error on my console logs as Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] . When I try to run the application , I encountered an error in the console log , Such as Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] . I have tried this on old version of hibernate and it worked. I've been in the old version of hibernate I tried this on , It worked . The hibernate version that I am using right now is version 5.1.0. The dormant version I'm using now is 5.1.0 edition . The following is the error log: Here is the error log : The following is my hibernate.cfg.xml file The following is mine hibernate.cfg.xml file <?xml version='1.0' encoding='utf-8'?><!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <!-- Database connection settings --> <property name="connection.driver_class">org.postgresql.Driver</property> <property name="connection.url">jdbc:postgresql://localhost:5432/hibernatedb</property> <property name="connection.username">sa</property> <property name="connection.password">password</property> <!-- JDBC connection pool (use the built-in) --> <property name="connection.pool_size">1</property> <!-- SQL dialect --> <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property> <!-- Enable Hibernate's automatic session context management --> <property name="current_session_context_class">thread</property> <!-- Disable the second-level cache --> <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property> <!-- Echo all executed SQL to stdout --> <property name="show_sql">true</property> <!-- Drop and re-create the database schema on startup --> <property name="hbm2ddl.auto">create</property> <!-- Names the annotated entity class--> <mapping class="org.javabrains.dto.UserDetails"/> </session-factory></hibernate-configuration>My POJO class my POJO course And my application class: My application class : package org.javabrains.hibernate;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.cfg.Configuration;import org.javabrains.dto.UserDetails;public class HibernateTest { public static void main(String[] args) { UserDetails user = new UserDetails(); user.setUserId(1); user.setUserName("Tet"); //Hibernate API to save this objects to DB //Session factory is created only ONCE SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); Session session = sessionFactory.openSession(); //create transaction session.beginTransaction(); session.save(user); //end the transaction session.getTransaction().commit(); //Closing the session session.close(); }}The following is the image of java hibernate structure Here is java hibernate chart Solution : Reference resources : https://stackoom.com/en/question/2SV5l 版权声明 |