-->
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: Schema-export doesn't work
PostPosted: Thu Nov 23, 2006 2:18 am 
Newbie

Joined: Thu Nov 23, 2006 1:46 am
Posts: 8
Location: Brussels
Hi all
i'm new to hibernate, i'm trying to do some example witch i found a book
but i have some problem:

but first here are some details

Hibernate version:3.2.0
Hibernate Location:H:\Java\hibernate-3.2
MySQL Driver location:H:\Java\dr
Build4.xml Location:H:\Java\Projects\workspace\calendar\work
Name and version of the database you are using:mysql 5.0
The generated SQL (show_sql=true): No idea
Debug level Hibernate log excerpt: No idea

first the target clean is not executed
second <look at stack trace >

Mapping documents:

com/manning/hq/ch04/Event.hbm.xml
com/manning/hq/ch04/Location.hbm.xml



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

Code:
package work.src.java.com.manning.hq.ch04;
import org.hibernate.*;
import org.hibernate.cfg.Configuration;
import java.util.*;

public class EventLoader {
   
   public static void main(String[] args) {
      
      Location location = new Location();
      location.setName("Hilton convention center");
      location.setAddress("950 Brussels north st.");
      
      Event event = new Event();
      event.setName("Annual meeting");
      event.setDuration(60);
      event.setStartDate(createDate(2006,12,6));
      
      Session session = null;
      SessionFactory sessionFactory = null;
      Transaction tx = null;
      
      try{
         Configuration configuration = new Configuration();
         //configur from the hibernate file : hibernate.cfg.xml
         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 saver");
      }catch(HibernateException he){
         try{
            if(tx !=null){
               tx.rollback();
            }
      
         }catch(HibernateException ignore){
            //ignore
         }

         throw he; //rethrow
      }finally{
         if(session !=null){
            try{
               sessionFactory.close();
            }catch (HibernateException he) {
               //nothing
            }
         }
         if (sessionFactory !=null){
            try {
               sessionFactory.close();
            } catch (HibernateException e) {
               //nothing
            }
         }
      }
   }

   private static Date createDate(int year, int month, int day) {
      Calendar calendar= Calendar.getInstance();
      calendar.set(year, month,day);
      return calendar.getTime();
   }

}
[\CODE]


<!-- build4.xml -->

Code:
<?xml version="1.0"?>
<project name="build4.xml" default="build">

   <property name="src.java.dir" value="src/java"/>
   <property name="build.classes.dir" value="build/classes"/>
   <property name="hibernate.lib.dir" location="h:/java/hibernate-3.2"/>
   <property name="mysql.jdbc.version" value="5.0.4"/>
   <property name="jdbc.driver.jar" value="h:/java/dr/mysql-connector-java-5.0.4-bin.jar"/>

   <import file="hibernate-build.xml"/>

   <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="clean">
         <delete dir="${build.classes.dir}"/>
   </target>
   
   <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="work.src.java.com.manning.hq.ch04.EventLoader">
            <classpath refid="runtime.classpath"/>
         </java>
   </target>
   
   <target name="schema-export" depends="compile">
            <echo>the schema-export target!!!</echo>
         <taskdef name="schemaExport"
            classname="org.hibernate.tool.hbm2ddl.SchemaExportTask" classpathref="runtime.classpath">
         </taskdef>
         <schemaexport config="${src.java.dir}/hibernate.cfg.xml"/>
         <echo>If you see this, it works!!!</echo>
   </target>

</project>

[/CODE]

hibernate.cfg.xml[\b]

Code:

<?xml version="1.0"?>
   <!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.username">root</property>
   <property name="connection.password"></property>
   <property name="connection.url"> jdbc:mysql://localhost/events_calendar </property>
   <property name="connection.driver_class"> com.mysql.jdbc.Driver </property>
   <property name="dialect"> org.hibernate.dialect.MySQLDialect </property>
   
   <mapping resource="com/manning/hq/ch04/Event.hbm.xml" />
   <mapping resource="com/manning/hq/ch04/Location.hbm.xml" />
</session-factory>
</hibernate-configuration>



[b]Full stack trace of any exception that occurs:
Buildfile: H:\Java\Projects\workspace\calendar\work\build4.xml
init:
compile:
[javac] Compiling 3 source files to H:\Java\Projects\workspace\calendar\work\build\classes
build:
[java] 2006-11-23 06:56:50,289 WARN JDBCExceptionReporter:SQL Error: 1146, SQLState: 42S02
[java] 2006-11-23 06:56:50,289 ERROR JDBCExceptionReporter:Table 'events_calendar.locations' doesn't exist
[java] org.hibernate.exception.SQLGrammarException: could not insert: [work.src.java.com.manning.hq.ch04.Location]
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:180)
[java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:710)
[java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:178)
[java] at org.apache.tools.ant.taskdefs.Java.execute(Java.java:84)
[java] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
[java] at org.apache.tools.ant.Task.perform(Task.java:364)
[java] at org.apache.tools.ant.Target.execute(Target.java:341)
[java] at org.apache.tools.ant.Target.performTasks(Target.java:369)
[java] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
[java] at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
[java] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
[java] at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
[java] at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
[java] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
[java] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
[java] Caused by: org.hibernate.exception.SQLGrammarException: could not insert: [work.src.java.com.manning.hq.ch04.Location]
[java] at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
[java] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
[java] at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:40)
[java] at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2093)
[java] at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2573)
[java] at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:47)
[java] at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
[java] at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:290)
[java] at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:180)
[java] at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:108)
[java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
[java] at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
[java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
[java] at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
[java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
[java] at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
[java] at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
[java] at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
[java] at work.src.java.com.manning.hq.ch04.EventLoader.main(Unknown Source)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[java] at java.lang.reflect.Method.invoke(Unknown Source)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:202)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:134)
[java] ... 14 more
[java] Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Table 'events_calendar.locations' doesn't exist
[java] at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
[java] at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)
[java] at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
[java] at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
[java] at com.mysql.jdbc.Connection.execSQL(Connection.java:3176)
[java] at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1153)
[java] at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1404)
[java] at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1318)
[java] at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1303)
[java] at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:73)
[java] at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33)
[java] ... 36 more
[java] --- Nested Exception ---
[java] org.hibernate.exception.SQLGrammarException: could not insert: [work.src.java.com.manning.hq.ch04.Location]
[java] at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
[java] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
[java] at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:40)
[java] at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2093)
[java] at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2573)
[java] at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:47)
[java] at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
[java] at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:290)
[java] at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:180)
[java] at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:108)
[java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
[java] at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
[java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
[java] at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
[java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
[java] at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
[java] at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
[java] at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
[java] at work.src.java.com.manning.hq.ch04.EventLoader.main(Unknown Source)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[java] at java.lang.reflect.Method.invoke(Unknown Source)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:202)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:134)
[java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:710)
[java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:178)
[java] at org.apache.tools.ant.taskdefs.Java.execute(Java.java:84)
[java] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
[java] at org.apache.tools.ant.Task.perform(Task.java:364)
[java] at org.apache.tools.ant.Target.execute(Target.java:341)
[java] at org.apache.tools.ant.Target.performTasks(Target.java:369)
[java] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
[java] at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
[java] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
[java] at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
[java] at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
[java] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
[java] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
[java] Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Table 'events_calendar.locations' doesn't exist
[java] at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
[java] at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)
[java] at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
[java] at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
[java] at com.mysql.jdbc.Connection.execSQL(Connection.java:3176)
[java] at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1153)
[java] at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1404)
[java] at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1318)
[java] at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1303)
[java] at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:73)
[java] at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33)
[java] ... 36 more
BUILD SUCCESSFUL
Total time: 3 seconds




Any help
thx
Mike
Code:


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 24, 2006 2:03 pm 
Newbie

Joined: Thu Nov 23, 2006 1:46 am
Posts: 8
Location: Brussels
no any idea?
i tryed even with out useing eclipse
Mike


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.