-->
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.  [ 11 posts ] 
Author Message
 Post subject: I need help with my hibernate.cfg.xml
PostPosted: Fri Mar 24, 2006 5:46 am 
Newbie

Joined: Fri Mar 24, 2006 5:20 am
Posts: 13
Location: Zaragoza
Hi everybody. First of all, I beg you pardon if my English isn't very good, and thank you for helping me.

I'm trying to mapping a single class and a table, so in order to do this I wrote the following hibernate.cfg.xml:

Code:
<?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>
      
      <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/taxis</property>
       <property name="connection.username">root</property>
        <property name="connection.password">fryGUY538</property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
       
        <!-- mapping files -->
   <mapping resource="Ni103_grid.hbm.xml"/>


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

I've written "connection.driver_class" instead of "hibernate.connection.driver class" because of I've read a post in which the problem was this, but it doesn't work for me.

Anyway, I try to run my small aplication in Eclipse and I get the following error message:

No connection properties specified - the user must supply JDBC connections
Exception in thread "main" org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:57)
at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:39)
at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:378)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:110)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1881)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1174)
at Principal.getSessionFactory(Principal.java:28)
at Gestor.main(Gestor.java:17)

I think that I have got every thing I need in my classpath, and my jdbc driver works for non-hibernate applications, so I'm a bit desperate.

I would appreciate your help.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 24, 2006 6:43 am 
Newbie

Joined: Wed Mar 15, 2006 10:14 am
Posts: 7
Location: France
Your message says you must provide a dialect. Your url connection seems a MySQL one, so you have to add
Code:
           <property name="hibernate.dialect">
         org.hibernate.dialect.MySQLDialect
      </property>

in your confg file.
hope this helps


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 24, 2006 6:54 am 
Newbie

Joined: Fri Mar 24, 2006 5:20 am
Posts: 13
Location: Zaragoza
No,this line is already in my document; this is the problem, I give Hibernate all the information, but he can't understand it. Thanks anyway.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 24, 2006 8:06 am 
Regular
Regular

Joined: Tue Nov 29, 2005 12:31 pm
Posts: 75
Hi,

Shouldn't it be in this way ?

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

<property name="hibernate.connection.url"></property>
<property name="hibernate.default_schema"></property>
<property name="hibernate.connection.username"></property>
<property name="hibernate.connection.password"></property>

<property name="dialect"></property>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 24, 2006 8:21 am 
Newbie

Joined: Fri Mar 24, 2006 5:20 am
Posts: 13
Location: Zaragoza
No, I'm still answered by the same error message. Thanks anyway.

For now I think this error perhaps isn't in the xml document because if I get out this file from my directory and try to run I still get the same error.

So, perhaps is another kind of problem; it's like the hibernate.cfg.xml couldn't be read, but if it is placed in my source foulder this can't be possible, can it? I mean, no classpath stuff at all?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 24, 2006 9:00 am 
Regular
Regular

Joined: Tue Nov 29, 2005 12:31 pm
Posts: 75
Hi,

Please post the code where you create the SessionFactory (and your configuration object).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 24, 2006 9:13 am 
Newbie

Joined: Fri Mar 24, 2006 5:20 am
Posts: 13
Location: Zaragoza
My POJO class is:


Code:
public class Ni103_grid{

   private String gridId;
   private String parent;
   private String description;
   private Double latitude;
   private Double lenght;
   
   public Ni103_grid (){};
   
   public String getGridId(){
      return gridId;
   }
   
   public void setGridId (String gridId){
      this.gridId=gridId;
   }
   
   public String getParent(){
      return parent;
   }
   
   public void setParent (String parent){
      this.parent=parent;
   }
   
   public String getDescrition(){
      return description;
   }
   
   public void setDescription (String description){
      this.description=description;
   }
   
   public Double getLatitude(){
      return latitude;
   }
   
   public void setLatitude (Double latitude){
      this.latitude=latitude;
   }
   
   public Double getLenght(){
      return lenght;
   }
   
   public void setLenght (Double lenght){
      this.lenght=lenght;
   }
   
}


and the code where I get my Session Factory is:

Code:
import org.hibernate.*;
import org.hibernate.cfg.*;

public class Principal {

   Configuration configuration= null;
   SessionFactory sessionFactory=null;
   Session session = null;
   
   public Principal (){};
   
   public Configuration getConfiguration(){
      if (configuration==null){
         configuration = new Configuration();
         try {
            configuration.addClass(Ni103_grid.class);
         }
         catch (MappingException e){
            
         }
      }
      return configuration;
   }
   
   public SessionFactory getSessionFactory() {
      if (sessionFactory==null){
         try {
            sessionFactory = getConfiguration().buildSessionFactory();
         }
         catch (HibernateException e){
            
         }
      }
      return sessionFactory;
   }


   public Session getSession() {
      if (session==null || !session.isOpen()){
         try {
            session=getSessionFactory().openSession();
         }
         catch (HibernateException e){
            
         }
      }
   return session;
   }
   
   public void insertar (String gridId, String parent, String description,Double latitude,Double lenght){
      
      
      
      Ni103_grid ni103_grid = new Ni103_grid();
      ni103_grid.setGridId(gridId);
      ni103_grid.setParent(parent);
      ni103_grid.setDescription(description);
      ni103_grid.setLatitude(latitude);
      ni103_grid.setLenght(lenght);
      
      
      Session session= getSession();
      
      
      Transaction tx = null;
      
      // Iniciamos una unidad de trabajo
      
      try{
         tx = session.beginTransaction();
         
         session.save(ni103_grid);
         
         
         tx.commit();
      }
      
      catch (HibernateException e){
         if (tx !=null) {
            try {
               tx.rollback();
            }
            catch (HibernateException f){
            }
         }
      }
      finally {
         {try
            session.close();
            }
         catch (HibernateException e){
         }
      }
   }
   
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 24, 2006 10:14 am 
Regular
Regular

Joined: Tue Nov 29, 2005 12:31 pm
Posts: 75
Hi,

private String configurationFile = "C:\<your path>\hibernate.cfg.xml";

public SessionFactory getSessionFactory() {
if (sessionFactory==null){
try {
sessionFactory = getConfiguration().configure(configurationFile).buildSessionFactory();
}
catch (HibernateException e){

}
}
return sessionFactory;
}

Enjoy ;)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 25, 2006 11:17 am 
Newbie

Joined: Sat Mar 25, 2006 10:09 am
Posts: 1
Location: Atlanta, Georgia
Pala:

The Javadocs API for class org.hibernate.cfg.Environment is a good place to look for the formats and definitions of the configuration properties.

Also, place your hibernate.cfg.xml file on the classpath. I put my file in the classpath root, not within a package. Also make sure you call the Configuration object's configure() method.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 26, 2006 12:24 am 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
if you use

Code:
SessionFactory sf=new Configuration().buildSessionFactory();


then this will use the hibernate.properties

if you use:
Code:
SessionFactory sf=new Configuration().configure().buildSessionFactory();


Then this will use the hibernate.cfg.xml

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 27, 2006 2:18 am 
Newbie

Joined: Fri Mar 24, 2006 5:20 am
Posts: 13
Location: Zaragoza
Yes, it worked. Thanks a lot!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 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.