-->
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: Hibernate Tools + Eclipse elementary problem
PostPosted: Tue Mar 01, 2005 5:42 pm 
Newbie

Joined: Tue Mar 01, 2005 5:00 pm
Posts: 11
Hello, this is my firs time that I use Hibernate.
At first I apologise by my English because I'm spanish and I don't write it very well.
I have spend some time reading forum posts but I can't resolve my problem

Hibernate 3
Hibernate Tools 3
Eclipse 3.1.M4
HSQL 1.7.3.3

I have created a database called "catdb" with one table called "CAT" with two columns "id" and "nom".
I have created a java project in Eclipse.
I have set all necesarie .jar correctly.
I have created "hibernate.cfg.xml" with hibernate tool wizard.
I have created the console with hibernate tool wizard.
I have use hibernate artifact generation wizard to generate all necessary files.
I have created "principal.java" class that instantiate "Cat.java", set its atributes and save the instance in "catdb" database.

All correct and no problem here, but... When I click on the play button I get this message:

Code:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.HibernateException: The dialect was not set. Set the property hibernate.dialect.
   at org.hibernate.dialect.Dialect.getDialect(Dialect.java:461)
   at org.hibernate.dialect.Dialect.getDialect(Dialect.java:483)
   at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:50)
   at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1485)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1029)
   at scr.principal.main(principal.java:31)


All files, except "principal.java" are been generated automactly by Hibernate Tool Wizard. My code files are:

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="hibernate.connection.url">jdbc:hsqldb:catdb</property>
        <property name="hibernate.cglib.use_reflection_optimizer">true</property>
        <property name="hibernate.connection.username">sa</property>
        <property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
        <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
<mapping resource="Cat.hbm.xml"/>
    </session-factory>
</hibernate-configuration>


Cat.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<!--
   Auto-generated mapping file from
   the hibernate.org cfg2hbm engine
-->
<class
    name="Cat"
    table="CAT"
>
   <id
        name="Id"
        type="java.lang.String"
    >
       <column name="ID" length="32" not-null="true" unique="true" sql-type="VARCHAR" />
       <generator class="assigned" />
    </id>
   
    <property
        name="Nom"
        type="java.lang.String"
    >
        <column name="NOM" length="32" not-null="true" sql-type="VARCHAR" />
   </property>

</class>
</hibernate-mapping>


Cat.java

Code:
package scr;

/**
* Cat generated by hbm2java
*/
public class Cat implements java.io.Serializable {

    // Fields   

    private java.lang.String Id;
    private java.lang.String Nom;

    // Constructors

    /** default constructor */
    public Cat() {
    }
   
    /** constructor with id */
    public Cat(java.lang.String Id) {
        this.Id = Id;
    }

    // Property accessors
    /**
     */
   public java.lang.String getId () {
        return this.Id;
    }
   
   public void setId (java.lang.String Id) {
        this.Id = Id;
    }
    /**
     */
   public java.lang.String getNom () {
        return this.Nom;
    }
   
   public void setNom (java.lang.String Nom) {
        this.Nom = Nom;
    }

}


principal.java
Code:
/*
* Creado el 01-mar-2005
*
* TODO Para cambiar la plantilla de este archivo generado, vaya a
* Ventana - Preferencias - Java - Estilo de código - Plantillas de código
*/
package scr;

//import Cat;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

/**
* @author Javier
*
* TODO Para cambiar la plantilla de este comentario generado, vaya a
* Ventana - Preferencias - Java - Estilo de código - Plantillas de código
*/
public class principal {

   public static void main(String[] args) throws Exception {
      
         Cat gat = new Cat();
         gat.setId("id1");
         gat.setNom("caty");
      
         Configuration cfg = new   Configuration().addClass(Cat.class);
         SessionFactory sf = cfg.buildSessionFactory();
         Session sess = sf.openSession();
         Transaction t = sess.beginTransaction();
         sess.save(gat);
         t.commit();
         sess.close();
      }

}


What can I do?

Thank you in advance


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 6:21 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
you have to edit hibernate.properties (or hibernate.cfg.xml) and set your databases

advice : use eclipse 3.1 m5 (or m5a) - annotations doesn't work with 3.1m4

in eclipse 3.1 m5 annotations work fine (compile, syntax , auto import) - documenatation
for annotation is deprecated (assert that eclipse doesn't work this )

regards


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 7:15 pm 
Newbie

Joined: Tue Mar 01, 2005 5:00 pm
Posts: 11
Hello, thank you for response so quickly but...

I don't understand you when you say "...set your databases."

Where is the mistake in my "hibernate.cfg.xml"?
I have to append/delete something?
The parameters of my hsql database are set in "hibernate.cfg.xml", I think.

Thank you another time.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 8:05 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you just call configuration.buildsessionfactory.

if hibernate.cfg.xml is not in the root of your classpath it doesnt get picked up.

you either move it into the root or call cfg.configure(pathtocfg.xml)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 02, 2005 3:34 am 
Newbie

Joined: Tue Feb 22, 2005 11:51 am
Posts: 18
you also have to set a password, i think


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 02, 2005 2:05 pm 
Newbie

Joined: Tue Mar 01, 2005 5:00 pm
Posts: 11
Hello for all:

for snpesnpe: I continue without knowing what's wrong in my hibernate.cfg.xml.
Now, I'm downloadins Eclipse 3.1.M5 to try.

for max: This is my work directory:

-hbn3

-scr
-Cat.java
-principal.java
-Cat.hbm.xml
-hibernate.cfg.xml
-jars,libs,etc.

When you talk about Classpath, what classpath you reference? windows classpath variable our exists another classpath variable especific for eclipse that I have to set?

"...call cfg.configure(pathtocfg.xml)" where have I to write this?

for seb: My HSQL haven't password.

Thank you!!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 02, 2005 2:48 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
You check root directories (source folders in eclipse project) and if you have hibernate.cfg.xml
delete hibernate.properties - maybe hibernate get hibernate.properties (if exists) before
hibernate.cfg.xml

hibernate.properties exists in hibernate test, tools and annotation test etc


I use m5 for annotations only - m4 donesn't work with annotations (compile)

regards


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 02, 2005 3:44 pm 
Newbie

Joined: Tue Mar 01, 2005 5:00 pm
Posts: 11
Hello snpesnpe,

I don't have any hibernate.properties file anywhere but the error "...The dialect was not set. Set the property hibernate.dialect." seems like the system is searching the file "hibernate.dialect" or "hibernate.properties" or "log4j.properties" and I don't have these files because all properties to connect to de database are in "hibernate.cfg.xml"

I've tried change
"Configuration cfg = new Configuration().addClass(Cat.class); " by
"Configuration cfg = new Configuration().configure().addClass(Cat.class); "

because I've read in the API " A new Configuration will use the properties specified in hibernate.properties by default" and I don't have this file. In the API specificates that to use "hibernate.cfg.xml" I've to use "configure()" and this take by default "hibernate.cfg.xml".

Ok, but when I make this change message error says the "hibernate.cfg.xml" not found.

Is this important?

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 02, 2005 5:23 pm 
Newbie

Joined: Tue Mar 01, 2005 5:00 pm
Posts: 11
Thank you very much all.

Reading some posts in the forum finally I've resolved my problem and my simply program runs.

Soon I will return with more problems... ;-)


Top
 Profile  
 
 Post subject: What was the solution?
PostPosted: Fri Mar 04, 2005 7:33 pm 
Beginner
Beginner

Joined: Fri Mar 04, 2005 7:12 pm
Posts: 34
How did you solve the problem? I had identical situation - logger configuration not picked up until I moved log4j.properties from top root level of the Eclipse project, which resolved the logger issue, but I have your same problem with the hibernate.cfg.xml file not being detected. Using Eclipse 3.1M5a and Hibernate 3.0rc1 on Macintosh OSX 10.3.8.

Directory structure:

Code:
-Hibernate to SQL Server
---src
--------mike.dean
------------base
----------------base DAO files from Hibernate Synchronizer
------------dao
----------------DAO files that I edit if I ever get to that stage
------------FormData.java (persistence class)
------------QueryTester.java (contains my main, which tries to open session)
------------a few other files in package mike.dean directory
--------log4j.properties  (gets picked up properly by app)
--------hibernate.cfg.xml (not found by application)


I have moved the hibernate.cfg.xml file to be outside the src folder, to be inside the mike.dean package, and where it is shown above, which is in the src folder. In all cases, printout as below indicating (I think) that the file was not detected properly:

Code:
15:35:29,445  INFO Environment:456 - Hibernate 3.0rc1
15:35:29,468  INFO Environment:469 - hibernate.properties not found
15:35:29,481  INFO Environment:502 - using CGLIB reflection optimizer
15:35:29,498  INFO Environment:532 - using JDK 1.4 java.sql.Timestamp handling
15:35:29,515  INFO Configuration:844 - processing extends queue
15:35:29,525  INFO Configuration:848 - processing collection mappings
15:35:29,534  INFO Configuration:857 - processing association property references
15:35:29,543  INFO Configuration:884 - processing foreign key constraints
Exception in thread "main" org.hibernate.HibernateException: The dialect was not set. Set the property hibernate.dialect.
   at org.hibernate.dialect.Dialect.getDialect(Dialect.java:474)
   at org.hibernate.dialect.Dialect.getDialect(Dialect.java:496)
   at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:51)
   at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1497)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1041)
   at mike.dean.QueryTester.main(QueryTester.java:20)


Thanks for your help.

_________________
J. Michael Dean, MD


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 07, 2005 1:33 pm 
Newbie

Joined: Tue Mar 01, 2005 5:00 pm
Posts: 11
My problem was that my code says:

...
Configuration cfg = new Configuration().addClass(Cat.class);
...

And my hibernate.cfg.xml:

...
<property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
<mapping resource="Cat.hbm.xml"/>
</session-factory>
</hibernate-configuration>
...

The error was that I was mapping two times the same thing.

Try this and say us!

Good luck!


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.