Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: unable to connect to MySQL
PostPosted: Tue Aug 08, 2017 2:51 am 
Beginner
Beginner

Joined: Tue Aug 08, 2017 12:14 am
Posts: 20
Hi,

This is the first time I am using Hibernate so I hope to get some help here.

Basically, I am using hibernate on top of JPA via EclipseLink with Tomcat 8.

Here's the error I got :

Code:
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:48)
   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)


I am not sure if the configuration file is not done properly hence the error. Pls take a look

Code:
<?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>


and my persistence.xml

Code:
<?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>



Also, in my case I wonder do I need to do the reverse engineering before the data can be inserted? I am using annotation by the way.


Top
 Profile  
 
 Post subject: Re: unable to connect to MySQL
PostPosted: Sun Aug 13, 2017 2:15 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1433
Why do you have both a hibernate.cfg.xml and the JPA persistence.xml in your env? You should use only one config file.

Quote:
Basically, I am using hibernate on top of JPA via EclipseLink with Tomcat 8.


What do you mean when you say that you are using Hibernate on top of JPA via EclipseLink? Both Hibernate and EclipseLink are JPA implementations so you use either one or the other, but not both.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: unable to connect to MySQL
PostPosted: Sun Aug 13, 2017 4:57 am 
Beginner
Beginner

Joined: Tue Aug 08, 2017 12:14 am
Posts: 20
vlad wrote:
Why do you have both a hibernate.cfg.xml and the JPA persistence.xml in your env? You should use only one config file.

Quote:
Basically, I am using hibernate on top of JPA via EclipseLink with Tomcat 8.


What do you mean when you say that you are using Hibernate on top of JPA via EclipseLink? Both Hibernate and EclipseLink are JPA implementations so you use either one or the other, but not both.


Basically, I have annotations for many-to-many relationships in my POJOs.

And then I have Eclipse Link so I have persistence.xml created.

I am not using EntityManager but using Hibernate sessionFactory etc in my insert method in my DAOimpl class.


Configuration config = new Configuration().configure();
SessionFactory sessionFactory = config.buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction transaction = (Transaction) session.beginTransaction();

Another thing is that I am using a servlet class for reading in the parameters reading from my jsp. However, I am not sure if the container will do the necessary connection with the connection pooling infor I put in the persistence.xml.

Could you kindly advise me?

And the cause of the error I have shown is it due to the wrong server used ?


Top
 Profile  
 
 Post subject: Re: unable to connect to MySQL
PostPosted: Sun Aug 13, 2017 5:51 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1433
Quote:
And then I have Eclipse Link so I have persistence.xml created.

I am not using EntityManager but using Hibernate sessionFactory etc in my insert method in my DAOimpl class.


If you're using both EclipseLink and Hibernate in the same project, then you are doing it all wrong. For more details about the difference between JPA, Hibernate and EclipseLink, check out this StackOverflow answer.

Quote:
And the cause of the error I have shown is it due to the wrong server used ?


The answer lies in the actual error message:

Quote:
Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.


So, you have a networking issue.

Also, the DriverManagerConnectionProviderImpl is meant only for testing, not for a production environment. You did read the User Guide, right?

Quote:
Another thing is that I am using a servlet class for reading in the parameters reading from my jsp. However, I am not sure if the container will do the necessary connection with the connection pooling infor I put in the persistence.xml.


You either use the c3p0 or HikariCP Hibernate modules or use an external CP set up as a DataSource and passed to Hibernate. For more details, check out High-Performance Java Persistence.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: unable to connect to MySQL
PostPosted: Mon Aug 14, 2017 12:05 pm 
Beginner
Beginner

Joined: Tue Aug 08, 2017 12:14 am
Posts: 20
vlad wrote:
Quote:
And then I have Eclipse Link so I have persistence.xml created.

I am not using EntityManager but using Hibernate sessionFactory etc in my insert method in my DAOimpl class.


If you're using both EclipseLink and Hibernate in the same project, then you are doing it all wrong. For more details about the difference between JPA, Hibernate and EclipseLink, check out this StackOverflow answer.

Quote:
And the cause of the error I have shown is it due to the wrong server used ?


The answer lies in the actual error message:

Quote:
Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.


So, you have a networking issue.

Also, the DriverManagerConnectionProviderImpl is meant only for testing, not for a production environment. You did read the User Guide, right?

Quote:
Another thing is that I am using a servlet class for reading in the parameters reading from my jsp. However, I am not sure if the container will do the necessary connection with the connection pooling infor I put in the persistence.xml.


You either use the c3p0 or HikariCP Hibernate modules or use an external CP set up as a DataSource and passed to Hibernate. For more details, check out High-Performance Java Persistence.


Hello,

I will sure check out your book but after using c3p0 I am still getting the following error :

Code:
Could not obtain connection to query metadata : Unable to resolve name [org.hibernate.MySQLDialect] as strategy [org.hibernate.dialect.Dialect]
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:48)
   at Business.Manager.insertTutor(Manager.java:24)
   at controller.tutorController.doPost(tutorController.java:131)
   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.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.MySQLDialect] as strategy [org.hibernate.dialect.Dialect]
   at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:126)
   at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveStrategy(StrategySelectorImpl.java:194)
   at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveDefaultableStrategy(StrategySelectorImpl.java:152)
   at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveDefaultableStrategy(StrategySelectorImpl.java:139)
   at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveStrategy(StrategySelectorImpl.java:133)
   at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.constructDialect(DialectFactoryImpl.java:74)
   at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:51)
   at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137)
   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
java.lang.NullPointerException
   at controller.tutorController.doPost(tutorController.java:146)
   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)


And here's my improved hibernate.cfg.xml :

Code:
<hibernate-configuration>
<session-factory>
            <!-- Database connection settings -->
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="connection.url">jdbc:mysql://localhost:3306/hi5</property>
    <property name="connection.username">root</property>
    <property name="connection.password">root</property>
   <!-- JDBC connection pool (use the built-in) -->
    <property name="connection_pool_size">true</property>


<!-- Use the C3P0 connection pool. --> 
        <property name="c3p0.min_size">3</property> 
        <property name="c3p0.max_size">5</property> 
        <property name="c3p0.timeout">1800</property>
   
   <!-- SQL dialect -->
    <property name="hibernate.dialect">org.hibernate.MySQLDialect</property>

    <!-- Disable the second-level cache -->
    <property name="cache.provider_class">org.hibernate.NoCacheProvider</property>

    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">1</property>
</session-factory>
</hibernate-configuration>   


There is nothing wrong with the spelling whatsoever but I am still getting Unable to resolve name [org.hibernate.MySQLDialect] as strategy [org.hibernate.dialect.Dialect]...

What is it that goes wrong ?

I doubt that this is caused by the EclipseLink that is sitting in my app also....


Top
 Profile  
 
 Post subject: Re: unable to connect to MySQL
PostPosted: Mon Aug 14, 2017 2:59 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1433
Quote:
There is nothing wrong with the spelling whatsoever but I am still getting Unable to resolve name [org.hibernate.MySQLDialect] as strategy [org.hibernate.dialect.Dialect]...


Of course it's because of a spelling mistake. If you read the message carefully you can easily spot the issue: the package name.

Instead of:

Code:
<property name="hibernate.dialect">org.hibernate.MySQLDialect</property>


you should have

Code:
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: unable to connect to MySQL
PostPosted: Wed Aug 16, 2017 2:21 am 
Beginner
Beginner

Joined: Tue Aug 08, 2017 12:14 am
Posts: 20
vlad wrote:
Quote:
There is nothing wrong with the spelling whatsoever but I am still getting Unable to resolve name [org.hibernate.MySQLDialect] as strategy [org.hibernate.dialect.Dialect]...


Of course it's because of a spelling mistake. If you read the message carefully you can easily spot the issue: the package name.

Instead of:

Code:
<property name="hibernate.dialect">org.hibernate.MySQLDialect</property>


you should have

Code:
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>


You are right. Tks.

But, I am still getting error :
Code:
Initial SessionFactory creation failed.org.hibernate.AnnotationException: Associations marked as mappedBy must not define database mappings like @JoinTable or @JoinColumn: model.Subject.tutors
Aug 16, 2017 12:41:12 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [tutorController] in context with path [/Hi5S] threw exception [Servlet execution threw an exception] with root cause
org.hibernate.AnnotationException: Associations marked as mappedBy must not define database mappings like @JoinTable or @JoinColumn: model.Subject.tutors
   at org.hibernate.cfg.annotations.CollectionBinder.bind(CollectionBinder.java:480)


Can I know if there's anything wrong with my annotation method ?

Code:
package model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.JoinColumn;

@Entity
@Table(name = "tutor")
public class Tutor implements Serializable{
   
   @Id
   @GeneratedValue(strategy=GenerationType.IDENTITY)
   
   @Column(name="tutor_id")
   private int tutor_id;
   
   @Column(name="tutorName")
   private String name;
   @Column(name="tutorIC")   
   private String NRIC;
   @Column(name="tutorGender")
   private String gender;
   @Column(name="tutorAddress1")
   private String address1;   
   //private String[] subject;
   @Column(name="tutorAge")
   private int age;
   so on and so for....
   String[] subjMany;// Can't use Subject subjMany cos I am using String[] subjMany to getParameterValues
   
   
   @ManyToMany(targetEntity=Subject.class, cascade = CascadeType.ALL)
   @JoinTable(name="tutor_subject",
    joinColumns={@JoinColumn(name="tutor_id")},             
  inverseJoinColumns={@JoinColumn(name="sub_id")})    
   
   
   private Collection<Subject> subjects;
   
   
   public Collection<Subject> getSubjects() {
      return subjects;
   }
   public void setSubjects(Collection<Subject> subjects) {
      this.subjects = subjects;
   }
   public void addSubject(Subject subject) {
        this.subjects.add(subject);
    }
   public String[] getSubjMany() {
      return subjMany;
   }
   public void setSubjMany(String[] subjMany) {
      this.subjMany = subjMany;
   }
   
   public int getTutor_id() {
      return tutor_id;
   }
   public int setTutor_id(int tutor_id) {
      return this.tutor_id = tutor_id;
   }
   public String getName() {
      return name;
   }
   
   
   public String[] getSubject() { // use subjMany because String [] subjMany in Subject
      return subjMany;
   }
   public void setSubject(String[] subjMany) {
      this.subjMany = subjMany;
   }
   
   getter and setter etc etc
}



Code:
@Entity
@Table(name = "subject")
public class Subject implements Serializable {

   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   @Column(name = "sub_id")
   private int sub_id;

   private String subj;

   @Column(name = "subjectName")
   private String[] subjMany;

   public String[] getSubjMany() {
      return subjMany;
   }

   public void setSubjMany(String[] subjMany) {
      this.subjMany = subjMany;
   }

   public Subject(int sub_id, String subj) {
      this.sub_id = sub_id;
      this.subj = subj;
   }

   public Subject() {
      // TODO Auto-generated constructor stub
   }

   @ManyToMany(mappedBy = "subjects", targetEntity = Tutor.class, cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
   @JoinTable(name = "tutor_subject", joinColumns = { @JoinColumn(name = "sub_id") }, inverseJoinColumns = {
         @JoinColumn(name = "tutor_id") })

   private Collection<Tutor> tutors;

   public Collection<Tutor> getTutors() {
      return tutors;
   }

   public void setTutors(Collection<Tutor> tutors) {
      this.tutors = tutors;
   }

   
   public int getSub_id() {
      return sub_id;
   }

   public void setSub_id(int sub_id) {
      this.sub_id = sub_id;
   }



Top
 Profile  
 
 Post subject: Re: unable to connect to MySQL
PostPosted: Wed Aug 16, 2017 2:47 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1433
If you read the Hibernate User Guide, you'll find the answer to this question as well as thousands of answers to many more questions you'll have if you don't read it.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: unable to connect to MySQL
PostPosted: Thu Aug 17, 2017 12:41 am 
Beginner
Beginner

Joined: Tue Aug 08, 2017 12:14 am
Posts: 20
vlad wrote:
If you read the Hibernate User Guide, you'll find the answer to this question as well as thousands of answers to many more questions you'll have if you don't read it.


Thank you for directing me to the user guide.

However, I am puzzled why at the many-to-many bidirectional example, there is no 'annotation' indication of merging table ?
How does the engine know about the link table name in the database ?


Top
 Profile  
 
 Post subject: Re: unable to connect to MySQL
PostPosted: Thu Aug 17, 2017 2:05 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1433
Of course, it knows.

Check out this article for more details.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: unable to connect to MySQL
PostPosted: Fri Aug 18, 2017 1:30 am 
Beginner
Beginner

Joined: Tue Aug 08, 2017 12:14 am
Posts: 20
vlad wrote:
Of course, it knows.

Check out this article for more details.


I notice that you did not use Serializable in your POJO.

Is not not ok to use Serializable in hibernate framework ?


Top
 Profile  
 
 Post subject: Re: unable to connect to MySQL
PostPosted: Fri Aug 18, 2017 2:22 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1433
You can use Serializable with your entities.

I didn't use it because I did not need it. You only need Serializable if you plan to marshal/unmarshal entities or store them in the HttpSession. In my case, it's just a simple example that aims to demonstrate one JPA or Hibernate feature that's relevant for the article.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.