-->
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.  [ 4 posts ] 
Author Message
 Post subject: error: The dialect was not set
PostPosted: Sat Dec 18, 2004 9:28 pm 
Newbie

Joined: Thu Dec 02, 2004 3:22 am
Posts: 3
Location: Edmonton, Alberta, Canada
Hibernate version: 2.1

Mapping documents:src/hibernate.cfg.xml, src/Record.hbm.xml

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:N/A

Name and version of the database you are using:MySQL

The generated SQL (show_sql=true):N/A

Debug level Hibernate log excerpt:N/A

Hello, I'm trying to export a schema using hbm2ddl.
I'm getting an error of: Schema text failed: The dialect was not set. Set the property hibernate.dialect.

My hibernate.cfg.xml file is configured like this:

Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration
   PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
   
<hibernate-configuration>

   <session-factory>
   
   <property name="hibernate.connection.datasource">java:comp/env/jdbc/vinyl</property>
   <property name="hibernate.show_sql">true</property>
   <property name="hibernate.dialect">net.sf.hibernate.dialect.MySQLDialect</property>
   
   <!-- Mapping files -->
   <mapping resource="Record.hbm.xml"/>
   
   </session-factory>
   
</hibernate-configuration>


I don't understand why it's complaining about not having the dialect set.

This is my first crack at Hibernate, so I have a very basic setup - just the hibernate configuration file and one mapping file - Record.hbm.xml

After getting stuck on this for a while, I created the database by hand.
I was able to use hibernate's tools to generate the .java file for my only class, Record.

I have a Struts action and I'm able to save to the database without problems. It'd be awfully nice to be able to generate the database structure using a script.

My ant script is as follows:

Code:
<?xml version="1.0"?>
<!-- ======================================================================
     Dec 18, 2004 1:55:48 PM                                                                                                                    ====================================================================== -->
<project name="vinyl" default="Generate_Java_Code" basedir=".">
   
   <property name="source.root" value="src" />
   <property name="class.root" value="classes" />
   <property name="lib.dir" value="WebRoot/WEB-INF/lib" />
   
   <path id="project.class.path">
      <pathelement location="${class.root}" />
      <fileset dir="${lib.dir}">
         <include name="*.jar"/>
      </fileset>
   </path>
   
   <taskdef name="hbm2java"
         classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask"
         classpathref="project.class.path" />
   
    <target name="Generate_Java_Code" description="Generate Java source from the O/R mapping files">       
       <hbm2java output="${source.root}">
          <fileset dir="${source.root}">
             <include name="**/*.hbm.xml" />
          </fileset>          
       </hbm2java>
    </target>
   
   <!-- Create runtime subdirectories and copy resources into them -->
   <target name="prepare" description="Sets up build structures">
      <mkdir dir="${class.root}" />
      
      <!-- Copy property files and O/R mappings for use at runtime -->
      <copy todir="${class.root}">
         <fileset dir="${source.root}">
            <include name="**/*.cfg.xml" />
            <include name="**/*.hbm.xml" />
         </fileset>
      </copy>
   </target>
   
   <!-- Compile the java source of the project -->
   <target name="compile" depends="prepare" description="Compiles all Java classes">
      <javac srcdir="${source.root}"
            destdir="${class.root}"
            debug="on"
            optimize="off"
            deprecation="on">
         <classpath refid="project.class.path" />
      </javac>
   </target>
   
   <target name="Build_DB_Schema" depends="compile" description="Generate dB schema from the O/R mapping files">   
   
      <!-- Use Hibernate's schema generation tool -->
      <taskdef name="schemaexport"
            classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask"
            classpathref="project.class.path" />
   
      <schemaexport properties="${class.root}/hibernate.cfg.xml"
               quiet="no" text="no" drop="no" delimiter=";" output="vinyl-schema.sql">
         <fileset dir="${class.root}">
            <include name="**/*.hbm.xml" />
         </fileset>
      </schemaexport>
   </target>   
   
</project>


Can anyone offer advice?

Thank you,

Rob


Top
 Profile  
 
 Post subject: hibernate.properties or hibernate.cfg.xml ?
PostPosted: Sun Dec 19, 2004 1:48 am 
Newbie

Joined: Thu Dec 02, 2004 3:22 am
Posts: 3
Location: Edmonton, Alberta, Canada
I updated by ant script to run the SchemaExport tool using hibernate.properties, instead of hibernate.cfg.xml.
The export tool stopped complaining about not having the dialect set.
However, I've run into a second problem.

My database connections are requested by Hibernate through JNDI. I'm following the Hibernate documentation (Ch. 1, pg. 2).

To make some progress in getting the schema to generate, I need to declare the datasource in the .properties file, so I did it like so:

hibernate.connection.datasource jdbc/vinyl
hibernate.connection.username rob
hibernate.connection.password 123456
hibernate.dialect net.sf.hibernate.dialect.MySQLDialect

Which results in:

Code:
Running hbm2ddl schema export
[schemaexport] 22:28:05,591  INFO SchemaExport:117 - exporting generated schema to database
[schemaexport] 22:28:05,622  INFO NamingHelper:26 - JNDI InitialContext properties:{}
[schemaexport] 22:28:05,622 FATAL DatasourceConnectionProvider:47 - Could not find datasource: jdbc/vinyl
[schemaexport] javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial


Does anyone have a hibernate.properties file handy that uses JNDI or can tell me what is wrong with my .properties file ?

The documentation I found on this site only shows how to set up a hibernate.cfg.xml file for JNDI - SchemaExport doesn't seem to like that configuration style.

-Rob


Top
 Profile  
 
 Post subject: Update: solved. Question - duplicate import ?
PostPosted: Sun Dec 19, 2004 3:18 am 
Newbie

Joined: Thu Dec 02, 2004 3:22 am
Posts: 3
Location: Edmonton, Alberta, Canada
I've managed to get the schema export off the ground and it works fine. I have a question.

After doing more digging around, I found that I should replace

Code:
<schemaexport properties="${class.root}/hibernate.cfg.xml"


with

Code:
<schemaexport config="${class.root}/hibernate.cfg.xml"


When I ran my ant script, I saw:

Code:

[schemaexport] 23:49:22,419  INFO Configuration:169 - Mapping file: C:\eclipse\workspace\vinyl\classes\Record.hbm.xml

[schemaexport] 23:49:22,466 ERROR Configuration:255 - Could not compile the mapping document
[schemaexport] net.sf.hibernate.MappingException: duplicate import: Record

[schemaexport] at net.sf.hibernate.cfg.Mappings.addImport(Mappings.java:85)
[schemaexport] at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:126)
[schemaexport] at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:221)



So it's as if the export tool was trying to generate the source for Record.hbm.xml twice.

hibernate.cfg.xml mentions Record.hbm.xml like so:

Code:
   <mapping resource="Record.hbm.xml" />


My ant script also refers to *.hbm.xml:

Code:
      <taskdef name="schemaexport"
            classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask"
            classpathref="project.class.path" />
   
      <schemaexport config="${class.root}/hibernate.cfg.xml"
               quiet="no"
               text="yes"
               drop="no"
               delimiter=";"
               output="${source.root}/schema.sql">
         <fileset dir="${class.root}">
            <include name="**/*.hbm.xml" />
         </fileset>
      </schemaexport>


I can get the export to work properly is if I change my ant script to

Code:
      <fileset dir="${class.root}">
            <include name="**/*.hbm.BLAH" />  <-- *note -->
         </fileset>


as if to make the tool "ignore" Record.hbm.xml that's copied into the /classes folder.

Can anyone see why that is so?

-Rob


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 19, 2004 6:23 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
well because if you add Record.hbm.xml twice it is considered an error. ;)

record.hbm.xml is both in cfg.xml and in your include list.

(in H3 and possibly H2.8 the requirement of listing a mapping is removed)

_________________
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.  [ 4 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.