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.  [ 2 posts ] 
Author Message
 Post subject: schemaexport problem
PostPosted: Mon Feb 05, 2007 2:16 am 
Newbie

Joined: Thu Nov 23, 2006 1:46 am
Posts: 8
Location: Brussels
Hey
Can someone help me with this error
i'm trying to create the tables using ANT schemaexport

here are the details

Hibernate version:3.1

Mapping documents:
Event.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 package="book.com.manning.hq.ch04">
    <class name="Event" table="events">
        <id name="id" column="uid" type="long">
            <generator class="native"/>
        </id>
        <property name="name" type="string"/>
        <property name="startDate" column="start_date"
            type="date"/>
        <property name="duration" type="integer"/>
        <many-to-one name="location" column="location_id" class="Location" cascade="save-update" />
    </class>
</hibernate-mapping>


Location.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 package="book.com.manning.hq.ch04">
    <class name="Location" table="locations">
        <id name="id" column="uid" type="long">
            <generator class="native"/>
        </id>
        <property name="name" type="string"/>
        <component name="address" class="Address" >
            <property name="streetAddress" column="street_address" type="string"/>
            <property name="city" type="string"/>
            <property name="state" type="string"/>
            <property name="zipCode" column="zip_code" type="string"/>
        </component>
    </class>
</hibernate-mapping>


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

Code:
package book.com.manning.hq.ch04;

import java.util.*;
import org.hibernate.*;
import org.hibernate.cfg.Configuration;



public class EventLoader {
   
   /*
    * wasem note: At the moment let us just cach the exceptions here
    */
   public static void main(String[] args) {
      
      Location location = new Location();
      //Location location = new book.com.manning.hq.ch04.Location();
      location.setName("Hilton Convention Center");
      location.setAddress("950 North Stafford St.");
      
      Event event = new Event();
      event.setName("Annual Meeting");
      event.setDuration(60);
      event.setStartDate(createDate(2004, 11, 1));
      event.setLocation(location);
      
      Session session = null;
      Transaction tx = null;
      SessionFactory sessionFactory = null;
      
      try {
         
         //session = MySessionFactory.getSession();
         
         Configuration configuration = new Configuration();
         //Configure from hibernate.cfg.xml
         //at root of classpath.
         configuration.configure();
         sessionFactory = configuration.buildSessionFactory();
         session = sessionFactory.openSession();
         tx = session.beginTransaction();
         session.save(location);
         session.save(event);
         session.flush();
         tx.commit();
         System.out.println("Event and location saved!");
      } catch (HibernateException he) {
         try {
               if(tx != null) {
                     tx.rollback();
               }
            } catch (HibernateException ignore) {
            // @Waseem notes: What can be done here??
            }
            throw he; // Rethro
      }finally {
         if (session != null) {
            try {
               session.close();
            } catch (HibernateException ignore) {
//             ignore
            }
         }
         if (sessionFactory != null) {
            try {
                  sessionFactory.close();
            } catch (HibernateException e) {
//             ignore
            }
         }
      }
   }
   
   /**
   * @param year
   * @param month - This is 0-based:
   * 0 = January, 11 = December
   * @param day
   * @return
   */
   private static Date createDate(int year, int month, int day) {
      Calendar calendar = Calendar.getInstance();
      calendar.set(year, month, day);
      return calendar.getTime();
   }
}


Full stack trace of any exception that occurs:

Code:
Buildfile: H:\Java\Projects\workspace\calendar2\build4.xml
clean:
   [delete] Deleting directory H:\Java\Projects\workspace\calendar2\build\classes
     [echo] Build dir has been cleaned!!!
init:
    [mkdir] Created dir: H:\Java\Projects\workspace\calendar2\build\classes
compile:
    [javac] Compiling 5 source files to H:\Java\Projects\workspace\calendar2\build\classes
schema-export:
[schemaexport] 06:53:31,015  INFO Environment:479 - Hibernate 3.1.2
[schemaexport] 06:53:31,015  INFO Environment:509 - hibernate.properties not found
[schemaexport] 06:53:31,031  INFO Environment:525 - using CGLIB reflection optimizer
[schemaexport] 06:53:31,031  INFO Environment:555 - using JDK 1.4 java.sql.Timestamp handling
[schemaexport] 06:53:31,093  INFO Configuration:1342 - configuring from file: hibernate.cfg.xml
[schemaexport] 06:53:31,171  INFO Configuration:469 - Reading mappings from resource: book/com/manning/hq/ch04/Event.hbm.xml

BUILD FAILED
H:\Java\Projects\workspace\calendar2\build4.xml:49: java.lang.NoClassDefFoundError: org/apache/commons/collections/SequencedHashMap

Total time: 1 second


Name and version of the database you are using:
MYSQL5

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">

<!-- Generated by MyEclipse Hibernate Tools.                   -->
<hibernate-configuration>

<session-factory>
   <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
   <property name="connection.url">jdbc:mysql://localhost/events_calendar</property>
   <property name="connection.username">root</property>
   <property name="connection.password">1122345</property>
   <property name="connection.driver_class">com.mysql.jdbc.Driver </property>
   
   <!-- Mapping files -->
   <mapping resource="book/com/manning/hq/ch04/Event.hbm.xml" />
   <mapping resource="book/com/manning/hq/ch04/Location.hbm.xml" />

</session-factory>

</hibernate-configuration>


build file:
build4.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<project name="build4.xml" default="build">
   <property name= "src.java.dir" location="src"/>
   <property name= "build.classes.dir" location= "build/classes"></property>
   <property name="hibernate.version" value="3.2"></property>
   
   <import file="hibernate-build.xml"/>
   
   <!-- Specifies the jdbc driver location -->
   <property name="jdbc.driver.jar"
      value="C:/Program Files/MySQL/mysql-connector-java-5.0.4/mysql-connector-java-5.0.4-bin.jar">
   </property>
   
   <path id="project.classpath">
      <pathelement location="${build.classes.dir}"/>
   </path>
   
   <path id="runtime.classpath">
      <path refid="project.classpath"/>
      <path refid="hibernate.lib.path"/>
      <pathelement location="${jdbc.driver.jar}"/>
      <pathelement location="${src.java.dir}" />
   </path>
   
   
   <target name ="init">
      <mkdir dir="${build.classes.dir}"/>
   </target>
   
   <target name ="compile" depends="init">
      <javac srcdir="${src.java.dir}"
         destdir="${build.classes.dir}">
         <classpath refid="hibernate.lib.path"/>
      </javac>
   </target>
   
   <target name="build" depends="compile" >
      <java classname="book.com.manning.hq.ch04.EventLoader">
         <classpath refid="project.classpath"/>
         <classpath refid="hibernate.lib.path"/>
      </java>
   </target>
   
   <target name="schema-export" depends="compile" >
      <taskdef name="schemaexport"
         classname="org.hibernate.tool.hbm2ddl.SchemaExportTask">
         <classpath refid="runtime.classpath" />
      </taskdef>
      <schemaexport config="src/hibernate.cfg.xml"/>
      <echo>Tables created!!!</echo>
   </target>

   <target name="clean">
         <delete dir="${build.classes.dir}"/>
         <echo>Build dir has been cleaned!!!</echo>
   </target>

</project>


the error pointing to the line:
Code:
<schemaexport config="src/hibernate.cfg.xml"/>
in build4.xml

I'm 4 days trying, reading , searching...etc please help
thx

Read this: http://hibernate.org/42.html
Code:
Code:


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 08, 2007 7:35 pm 
Newbie

Joined: Sun Dec 18, 2005 10:04 pm
Posts: 2
Quote:
BUILD FAILED
H:\Java\Projects\workspace\calendar2\build4.xml:49: java.lang.NoClassDefFoundError: org/apache/commons/collections/SequencedHashMap


Looks to me like you need commons-collections.jar in your classpath.


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