Hibernate configuration file

It seems that I have a problem with my configuration file but I really don't find out what it could be.

I used to use hibernate 3.6, I now use hibernate 4.2, there are proly some important changes that I ignore, but the doc seems to not change this part.

Here is my configuration file:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/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/Test</property>
        <property name="connection.username">root</property>
        <property name="connection.password">*****</property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">10</property>
        <property name="maxActive" value="10" />

        <!-- 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.internal.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 files -->
      <mapping resource="database/config/mapping/test.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

And here is my java source:

public class CreateDB {
    public static void main(String argv[]){
        try {
            Configuration configuration = new Configuration();
            configuration.configure("database/config/DBCreate.cfg.xml");
            ServiceRegistryBuilder serviceRegistryBuilder = new ServiceRegistryBuilder().applySettings(configuration
                .getProperties());
            SessionFactory sessionFactory = configuration
                .buildSessionFactory(serviceRegistryBuilder.buildServiceRegistry());
        DBConnect.Disconnect(null, sessionFactory.openSession()); // Just logout from a session
        } catch (Exception e) {
            System.out.println("Database unreachable.");
        }
    }
}

And here is the return statement:

mai 02, 2013 11:41:59 AM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
mai 02, 2013 11:41:59 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.0.Final}
mai 02, 2013 11:41:59 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
mai 02, 2013 11:41:59 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
mai 02, 2013 11:41:59 AM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: database/config/DBCreate.cfg.xml
mai 02, 2013 11:41:59 AM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: database/config/DBCreate.cfg.xml
Database unreachable.

I really don't get what is wrong, maybe someone will be able to enlight me. Sorry for possible disturbance and if my post isn't adapted, this is my first one.

Best regards.

Answers


Specify the port in the connection.url.

<property name="connection.url">jdbc:mysql://localhost:3306/Test</property>

I have read an article which says in Hibernate 4 we require to mention the "hibernate" keyword in the property name tag of the configuration file.

Sample format is -

Hibernate earlier version

    <?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="connection.url">jdbc:mysql://localhost/noob</property>

       <property name="connection.driver_class">com.mysql.jdbc.Driver</property>

       <property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>

       <property name="connection.username">root</property>
       <property name="connection.password"></property>

       <!-- DB schema will be updated if needed -->
       <property name="hbm2ddl.auto">create-drop</property>
       <property name="show_sql">false</property>
       <property name="format_sql">false</property>

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

Hibernate version 4

   <hibernate-configuration xmlns="http://www.hibernate.org/xsd/hibernate-
        configuration">

   <session-factory>
       <!-- Database connection settings -->
       <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
       <property name="hibernate.connection.url">jdbc:mysql://localhost/noob</property>
       <property name="hibernate.connection.username">root</property>

       <property name="hibernate.connection.password"></property>

       <!-- JDBC connection pool (use the built-in) -->
       <property name="hibernate.connection.pool_size">1</property>

       <!-- SQL dialect -->
       <property 
          name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>

        <!-- Enable Hibernate's automatic session context management -->
        <property name="hibernate.current_session_context_class">thread</property>

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

        <!-- Echo all executed SQL to stdout -->
        <property name="hibernate.show_sql">true</property>

        <!-- Drop and re-create the database schema on startup -->
        <property name="hibernate.hbm2ddl.auto">update</property>
    </session-factory>

   </hibernate-configuration>

Observe the "hibernate" keyword in the property name tag

The exact link is as follows -

hibernate.cfg.xml with Hibernate 4.0.0


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

When you change the XML file as per above comments, you must change the DTD definition.


Need Your Help

Why Hidden Fields value are not posted in mvc 4?

c# javascript .net asp.net-mvc asp.net-mvc-4

In my MVC-4 application i take location from geolocation using javaScript and set latitude, longiture and accuracy in Hidden Fields. Values are set correctly in Hidden fields but during PostBack it...

SwitchCompat change color

android android-support-library

I need to change SwitchCompat's track color.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.