Alex Rivera | Logout

Hibernate - ServiceRegistryBuilder

Asked 2011-12-27T02:20:22.590
19

I'm just trying to learn Hibernate (version 4 final) but I have a problem when trying to create the session factory. Here is some code related to the problem:

hibernate.cfg.xml:

<?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>
    <property name="connection.url">jdbc:mysql://localhost/fitterblog</property>
    <property name="connection.username">root</property>
    <property name="connection.password"></property>
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>

    <property name="connection.pool_size">1</property>
    <property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
    <property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
    <property name="current_session_context_class">thread</property>
    <property name="show_sql">true</property>

    <!--<mapping class="com.fitterblog.objects.Article"/>
    <mapping class="com.fitterblog.objects.Nav"/>
    <mapping class="com.fitterblog.objects.Tag"/>
    <mapping class="com.fitterblog.objects.User"/>-->

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


HibernateUtil.java:

public class HibernateUtil {

    private static final SessionFactory sessionFactory = buildSessionFactory();

    private static SessionFactory buildSessionFactory() {
        try {
            // Create the SessionFactory from hibernate.cfg.xml

            ServiceRegistryBuilder srb = new ServiceRegistryBuilder();

            //NOTE: THIS IS WHERE MY PROGRAM DIES!!
            srb = srb.configure();

            Se
Edit
Report

2 Answers

0

It might be just nitpicking, but please try replacing the DOCTYPE declaration in hibernate.cfg.xml with this:

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

Also, declare a name for the session-factory:

<session-factory name="java:hibernate/SessionFactory">
answered 2011-12-27T03:51:48.177
0

As answered in hibernate 4.0.0. CR4: org.hibernate.internal.util.config.ConfigurationException with hibernate.cfg.xml, the new way of creating SessionFactories doesn't work yet. It will be ready in Hibernate 4.1.

answered 2012-01-16T13:10:36.133

Your Answer