JAVA - error starting Hibernate application

Asked

Viewed 316 times

0

I am having problems starting my application with Hibernate. I am programming in Java using Eclipse.

Error message:

Sep 20, 2017 2:40:36 pm org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {5.2.11.Final} Sep 20, 2017 2:40:36 PM org.hibernate.cfg.Environment INFO: HHH000206: Hibernate.properties not found Sep 20, 2017 2:40:36 pm org.hibernate.boot.jaxb.Internal.stax.Localxmlresourceresolver resolveEntity WARN: HHH90000012: Recognized obsolete Hibernate namespace http://hibernate.sourceforge.net/hibernate-configuration. Use namespace http://www.hibernate.org/dtd/hibernate-configuration Instead. Support for obsolete DTD/XSD namespaces may be Removed at any time. Sep 20, 2017 2:40:36 pm org.hibernate.Annotations.common.Reflection.java.Javareflectionmanager INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final} Sep 20, 2017 2:40:36 PM org.hibernate.boot.jaxb.Internal.stax.Localxmlresourceresolver resolveEntity WARN: HHH90000012: Recognized obsolete Hibernate namespace http://hibernate.sourceforge.net/hibernate-mapping. Use namespace http://www.hibernate.org/dtd/hibernate-mapping Instead. Support for obsolete DTD/XSD namespaces may be Removed at any time. Sep 20, 2017 2:40:38 pm org.hibernate.engine.jdbc.Connections.internal.Drivermanagerconnectionproviderimpl configure WARN: HHH10001002: Using Hibernate built-in Connection pool (not for Production use!) Sep 20, 2017 2:40:38 PM org.hibernate.engine.jdbc.Connections.internal.Drivermanagerconnectionproviderimpl buildCreator INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql:192.168.0.0/CCIBD] Sep 20, 2017 2:40:38 PM org.hibernate.engine.jdbc.Connections.internal.Drivermanagerconnectionproviderimpl buildCreator INFO: HHH10001001: Connection properties: {user=root, password=***} Sep 20, 2017 2:40:38 PM org.hibernate.engine.jdbc.Connections.internal.Drivermanagerconnectionproviderimpl buildCreator INFO: HHH10001003: Autocommit mode: false Sep 20, 2017 2:40:38 PM org.hibernate.engine.jdbc.Connections.internal.Pooledconnections INFO: HHH000115: Hibernate Connection pool size: 1 (min=1) Initial Sessionfactory Creation failed.org.Hibernate.service.spi.Serviceexception: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.Jdbcenvironment] Exception in thread "main" java.lang.Exceptionininitializererror at Factory.HibernateUtil.(Hibernateutil.java:17) at Model.ModelUsuario.(Modelusuario.java:15) at Executables.ExeUsuario.main(Exeusuario.java:10)

Caused by: 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.configuraeService(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 Factory.HibernateUtil.(Hibernateutil.java:13) ... 2 more

Caused by: org.hibernate.Hibernateexception: Unable to make JDBC Connection [jdbc:mysql:192.168.0.0/CCIBD] at org.hibernate.engine.jdbc.Connections.internal.Basicconnectioncreator.createConnection(Basicconnectioncreator.java:60) at org.hibernate.engine.jdbc.Connections.internal.Pooledconnections.addConnections(Pooledconnections.java:123) at org.hibernate.engine.jdbc.Connections.internal.Pooledconnections.(Pooledconnections.java:42) at org.hibernate.engine.jdbc.Connections.internal.Pooledconnections.(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.configuraeService(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) ... 16 more

Hibernate.cfg.xml:

<!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 Dialect & Driver for Oracle 9G-->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property> 
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>

<!-- Database Details-->
<property name="connection.username">root</property>
<property name="connection.password">1997</property>
<property name="connection.url">jdbc:mysql:192.168.0.0/CCIBD</property>

<property name="connection.pool_size">1</property>
<property name="hibernate.default_schema">root</property>

<!-- Additional Properties -->
<property name="show_sql">true</property>

 <property name="hbm2ddl.auto">update</property>

<!-- Table Mapping --> 
<mapping resource="hibernate.hbm.xml"/>

</session-factory>
</hibernate-configuration>

Hibernate.hbm.xml:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate-mapping Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="HibUsuario" table="Usuario">
<meta attribute="class-description">
This class contains the USUARIO mapping.
</meta>

<id name="cpf" type="int" column="cpf">
 <generator class="native"/> 
</id>

<property name="usuario" type="string" column="usuario" not-null="true"/>
<property name="senha" type="string" column="senha" not-null="true"/>
<property name="permissao" type="string" column="permissao" not-null="true"/>

</class>

</hibernate-mapping>

Hibernateutil:

package Factory;


import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {

private static final SessionFactory sessionFactory;

static {
try {
    sessionFactory = new Configuration().configure().buildSessionFactory();
}
catch (Throwable ex){
    System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}

public static SessionFactory getSessionFactory(){
return sessionFactory;
}

}

Database:

create table Usuario(
cpf int not null,
usuario varchar(75),
senha varchar(25),
permissao varchar(30),
primary key(cpf),
constraint FK_FuncUser foreign key(cpf) references funcionarios(cpf)
);
  • <property name="connection.pool_size">1</property> me think 1 is very little. Put something between 5 and 10 and see if it works

  • It didn’t work, I tried all 5 to 10.

  • Your mysql address is this same 192.168.0.0? Usually end 0 and 255 are used for network broadcast. Make sure your mysql has the port enabled for your host.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.