NiB
NiB

Reputation: 949

Initial SessionFactory creation failed: org.hibernate.MappingException: invalid configuration

SOLVED

This question is about java hibernate.

When i run the Main class i get this error

Initial SessionFactory creation failed: org.hibernate.MappingException: 
invalid configuration
Exception in thread "main" java.lang.NullPointerException
at principal.ClienteDAO.guardaCliente(ClienteDAO.java:38)
at principal.Main.main(Main.java:31)
C:\Users\Nico\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 2 seconds)

Have no idea why im getting that exception

my hibernate.cfg.xml is

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-configuration>
<session-factory>
    <!--TODA LA INFORMACION FUE SACADA DE: http://www.javatutoriales.com/2009/05/hibernate-parte-1-persistiendo-objetos.html-->
    
    <!-- parametros para la conexion a la base de datos -->
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="connection.url">jdbc:mysql://localhost:3306/basededatosprueba</property>
    <property name="connection.username">root</property>
    <property name="connection.password"></property>
   
    <!-- Configuracion del pool interno -->
    <property name="connection.pool_size">1</property>
    
    <!-- Dialecto de la base de datos -->
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
    
    <!-- Otras propiedades importantes -->
    <property name="show_sql">true</property> 
    <property name="hbm2ddl.auto">create-drop</property>
    
    <!-- Archivos de mapeo -->
    <mapping resource="mapeos/Cliente.hbm.xml"/>
</session-factory>
</hibernate-configuration>

EDIT 2: So, i dont know why, but i change the hibernate.cfg.xml and now it works, here it is

<?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">com.mysql.jdbc.Driver</property>
    <property name="connection.url">jdbc:mysql://localhost:3306/basededatosprueba</property>
    <property name="connection.username">root</property>
    <property name="connection.password"></property>
    <!-- JDBC connection pool (use the built-in) -->
    <property name="connection.pool_size">1</property>
    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.MySQL5Dialect</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.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>

    <mapping resource="mapeos/Cliente.hbm.xml"/>
</session-factory>
</hibernate-configuration>

solved? we'll see

Upvotes: 0

Views: 1732

Answers (1)

Sam
Sam

Reputation: 680

I think you might need to close your hibernate-configuration tag in your xml.

Upvotes: 1

Related Questions