-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Hibernate Dialect must be explicitly set exception
PostPosted: Fri Jan 13, 2006 5:59 pm 
Newbie

Joined: Fri Jan 13, 2006 5:52 pm
Posts: 6
Hi, Hibernate newbie here. I am trying to set up my first Hibernate web project in Netbeans.

I have the cfg file properly in the root of my classpath:


<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<!-- a SessionFactory instance listed as /jndi/name -->
<session-factory>

<!-- properties -->
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
<property name="connection.url">jdbc:jtds:sqlserver://server/db</property>
<property name="connection.username">username</property>
<property name="connection.password">password</property>
<property name="use_outer_join">true</property>
<property name="transaction.factory_class">
net.sf.hibernate.transaction.JTATransactionFactory
</property>
<property name="jta.UserTransaction">java:comp/UserTransaction</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>

I have my HibernateUtil class configured to use an annotation configuration since that is what I want to try (I don't like the whole hassle of mapping files):

public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
sessionFactory = new AnnotationConfiguration()
.addPackage("com.cornerstone.datamodel")
.addAnnotatedClass(Contact.class)
.buildSessionFactory();

} catch (Throwable ex) {
// Log exception!
throw new ExceptionInInitializerError(ex.getMessage());
}
}
public static Session getSession() throws HibernateException {
return sessionFactory.openSession();
}
}

I get the "Hibernate Dialect must be explicitly set" exception when trying to run it, even though my dialect is explicitly set up in the config file.

exception

javax.servlet.ServletException: Servlet execution threw an exception
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)


root cause

java.lang.ExceptionInInitializerError: Hibernate Dialect must be explicitly set
com.cornerstone.HibernateUtil.<clinit>(HibernateUtil.java:21)



I am using the latest builds of Hibernate and Hibernate Annotations. I would appreciate any suggestions of what I might be doing wrong. All the necessary libs (i.e. all the hibernate jars and their dependencies as well as the JDBC driver) are in my Netbeans classpath for the project.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 13, 2006 6:07 pm 
Newbie

Joined: Fri Jan 13, 2006 5:52 pm
Posts: 6
I tested switching to a regular session (no annotations):

sessionFactory = new Configuration().configure().buildSessionFactory();

and it worked no problem (but of course I can't use my annotated classes with it). Is this a bug with Annotations in Hibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 13, 2006 6:22 pm 
Newbie

Joined: Fri Jan 13, 2006 5:52 pm
Posts: 6
Got it to work finally using this code

Code:
AnnotationConfiguration config = new AnnotationConfiguration();
            config.configure();
            sessionFactory = config
            .addPackage("com.cornerstone.datamodel")
            .addAnnotatedClass(Contact.class)
            .buildSessionFactory();


note the .configure();

Isn't this supposed to be automatic?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 13, 2006 7:13 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
eh no....it have always been required to call .configure() to load the default cfg.xml file.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 16, 2006 12:34 pm 
Newbie

Joined: Fri Jan 13, 2006 5:52 pm
Posts: 6
OK, thanks...this must be an issue with the HB docs then, since they explicity omit this:

Code:
    static {
        try {

            sessionFactory = new AnnotationConfiguration()
                    .addPackage("test.animals") //the fully qualified package name
                    .addAnnotatedClass(Flight.class)
                    .addAnnotatedClass(Sky.class)
                    .addAnnotatedClass(Person.class)
                    .addAnnotatedClass(Dog.class)
                    .buildSessionFactory();
        } catch (Throwable ex) {
            // Log exception!
            throw new ExceptionInInitializerError(ex);
        }
    }


See:
http://www.hibernate.org/hib_docs/annot ... figuration


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 16, 2006 12:47 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
well, that example does not require an hibernate.cfg.xml to work.

report it to the jira with a patch for the docs if you feel you have an better explanation.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.