0

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

2
  • suppose the exception is org.hibernate.MappingException and it may be helpful if you could share the Cliente.hbm.xml and pojo Commented May 20, 2017 at 1:14
  • ok, i edited it, so there is it :) Commented May 20, 2017 at 2:50

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

yes, i didnt notice it wasnt showing in the code, thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.