Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » How to use JPA and Hibernate together with Tomcat 8?(Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment])
How to use JPA and Hibernate together with Tomcat 8? [message #1769927] Sun, 06 August 2017 06:08 Go to next message
Karen Goh is currently offline Karen GohFriend
Messages: 18
Registered: February 2012
Junior Member
I got the following error which I do not know if I have done the configuration file wrongly. Hope someone can tell me where I had done wrongly. tks.

INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
	at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:271)
	at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:233)
	at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
	at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
	at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
	at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:242)
	at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
	at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
	at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
	at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
	at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
	at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:691)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726)
	at DAOSql.tutorDAOImpl.insertTutor(tutorDAOImpl.java:82)
	at Business.Manager.insertTutor(Manager.java:24)
	at controller.tutorController.doPost(tutorController.java:133)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)
Caused by: org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect
	at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:115)
	at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator$1$1.convert(BasicConnectionCreator.java:101)
	at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.convertSqlException(BasicConnectionCreator.java:123)
	at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:41)
	at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:58)
	at org.hibernate.engine.jdbc.connections.internal.PooledConnections.addConnections(PooledConnections.java:123)
	at org.hibernate.engine.jdbc.connections.internal.PooledConnections.<init>(PooledConnections.java:42)
	at org.hibernate.engine.jdbc.connections.internal.PooledConnections.<init>(PooledConnections.java:20)
	at org.hibernate.engine.jdbc.connections.internal.PooledConnections$Builder.build(PooledConnections.java:161)
	at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildPool(DriverManagerConnectionProviderImpl.java:109)
	at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:72)
	at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
	at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:242)
	at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
	at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:145)
	at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66)
	at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
	at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)
	at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:259)
	... 38 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
	at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:983)
	at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:628)
	at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1014)
	at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2254)
	at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2285)
	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2084)
	at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:795)
	at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
	at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:400)
	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:327)
	at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:38)
	... 53 more
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
	at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2949)
	at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:560)
	... 67 more
java.lang.NullPointerException
	at controller.tutorController.doPost(tutorController.java:148)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)


Here's the persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
	<persistence-unit name="Hi5S">
	 <provider></provider>
		<class>model.Subject</class>
		<class>model.Tutor</class>
		<properties>
			<property name="hibernate.connection.pool_size" value="1"/>
			<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
			<property name="show_sql" value="true"/>			
			<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false"/>             
     		<property name="eclipselink.ddl-generation.output-mode" value="database" />
     		<property name = "eclipselink.logging.level" value = "FINE"/>    
     		</properties>
	</persistence-unit>
	
</persistence>


Here's the hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
    
 
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.show_sql">false</property>
        <property name="hibernate.format_sql">true</property>
        <property name="use_sql_comments">false</property>
 
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost:8013/hi5"</property>
        <property name="connection.username">root</property>
        <property name="connection.password">"root"/</property>
 
        <!-- add classes to map from here -->
        <mapping class="hibernate.model.Tutor" />
        <mapping class="model.Subject" />
    </session-factory>
</hibernate-configuration>


Here's my TutorDAOImpl :

public class TutorDAOImpl implements TutorDAO {

	private EntityManagerFactory emf;
	@PersistenceContext(unitName = "tutor-unit")
	private EntityManager em ;
	

	public void insertTutor(Tutor m) throws Exception { 
		///  AnnotationConfiguration cfg = new AnnotationConfiguration();
			Configuration config = new Configuration().configure();
			SessionFactory sessionFactory = config.buildSessionFactory();
			Session session = sessionFactory.openSession();
			Transaction transaction = (Transaction) session.beginTransaction();
		//	em = emf.createEntityManager();	
		//	em.getTransaction().begin();
		  	m = new Tutor();
			m.setName(m.getName());
			m.setEmail(m.getEmail());
			m.setAddress1(m.getAddress1());
			.....
			session.save(m);
			transaction.commit();
			//em.getTransaction().commit();
		//	em.persist(m);
			}
Re: How to use JPA and Hibernate together with Tomcat 8? [message #1770177 is a reply to message #1769927] Tue, 08 August 2017 20:58 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
I'm confused as to why you would post a Hibernate error on an EclipseLink forum. EclipseLink is a JPA provider, as is Hibernate. Did you mean to post to the Eclipse IDE forum?
Also, your code isn't using JPA at all - this is Hibernate api outside of JPA.

Best Regards,
Chris
Re: How to use JPA and Hibernate together with Tomcat 8? [message #1770968 is a reply to message #1770177] Sun, 20 August 2017 05:42 Go to previous messageGo to next message
Karen Goh is currently offline Karen GohFriend
Messages: 18
Registered: February 2012
Junior Member
Hi Chris,

Tks for your reply but I have learnt that I can't mixed EclipseLink with Hibernate now.
The thing is that I thought EClipseLInk JPA is the annotation portion where I annotate the ManyToMany at the specific fields. And hibernate is responsible for persisting the data into the database.
Could you advise me if it is possible to use EclipseLink JPA solely for the bridging table ?

Do I just configure with a persistence.xml and the necessary annotations at the POJO and using the EntityManagerFactory method to save ?
Re: How to use JPA and Hibernate together with Tomcat 8? [message #1771053 is a reply to message #1770968] Mon, 21 August 2017 14:03 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
I'm a bit confused by what you are looking for. EclipseLink and Hibernate are both JPA providers, responsible for persisting data to the database - annotations are just a way of telling them how to map this data to the database.

You would need to specify the JPA provider you want to have handle your persistence unit within the <provider></provider> tag - otherwise the classloader will just go through JPA providers and pick the first. Try specifying:
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
As well as some of the JDBC specifics as shown here:
https://www.eclipse.org/eclipselink/documentation/2.5/solutions/testingjpa002.htm

With that, you can then us EclipseLink as your JPA provider, and obtain EntityManagerFactory/EntityManager instances to handle CRUD operations independently from your native Hibernate config/useage.
Re: How to use JPA and Hibernate together with Tomcat 8? [message #1773195 is a reply to message #1771053] Sat, 23 September 2017 07:38 Go to previous messageGo to next message
Karen Goh is currently offline Karen GohFriend
Messages: 18
Registered: February 2012
Junior Member
Hi Chris,

Thanks for your reply.

Now, I also learnt that Java has it's own JPA API. Correct me if I am wrong.

What if I just want to use Java inherent JPA with hibernate, do I still need to install EcliplseLink in Eclipse in order for the Java JPA aka annotation to work ?

Be'cos right now, I kept getting a message :

No connection specified for project. No database-specific validation will be performed. JPA Problem

even though I have all the datasource configuration like context.xml, persistence.xml, web.xml done correctly.


Re: How to use JPA and Hibernate together with Tomcat 8? [message #1773366 is a reply to message #1773195] Tue, 26 September 2017 21:17 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
I'm sorry, but I do not understand your question or what you are after. My guess is that you are using the Eclipse IDE, javax.persistence annotations (JPA) and use Hibernate under the covers as your JPA provider. JPA is just an interface and you need to make sure it and your provider's classes are on the classpath just like any other library. You will have to check Hibernate and its docs for your error and what you are doing incorrectly.

Best of luck,
Chris
Re: How to use JPA and Hibernate together with Tomcat 8? [message #1773636 is a reply to message #1773366] Mon, 02 October 2017 06:05 Go to previous message
Karen Goh is currently offline Karen GohFriend
Messages: 18
Registered: February 2012
Junior Member
Chris Delahunt wrote on Tue, 26 September 2017 17:17
I'm sorry, but I do not understand your question or what you are after. My guess is that you are using the Eclipse IDE, javax.persistence annotations (JPA) and use Hibernate under the covers as your JPA provider. JPA is just an interface and you need to make sure it and your provider's classes are on the classpath just like any other library. You will have to check Hibernate and its docs for your error and what you are doing incorrectly.

Best of luck,
Chris


Hi Chris,

Tks for highlighting to me that the JPA is just an interface. I thought that the concrete class for JPA would be coming from javaee-api.

So, could you let me know from here it's either I use hibernate or eclipselink to do the JPA ?

Cos now my problem is that Eclipse keeps give me a JPA error :

No database-specific validation will be performed.

And I am wondering if I should activate EclipseLink to enable the connection and then still use Hibernate for doing the insertion etc.
Previous Topic:Performance problem when doing merge
Next Topic:Wildfly 10 - The cost of creating the first eclipselink EntityManager during deployment is extremell
Goto Forum:
  


Current Time: Tue Mar 19 04:46:46 GMT 2024

Powered by FUDForum. Page generated in 0.03886 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top