-->
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: Database table does not generated using schemaexport
PostPosted: Thu Aug 18, 2005 5:18 am 
Newbie

Joined: Wed Aug 10, 2005 8:55 am
Posts: 2
Location: India
Hi,

My hibernate mapping file, Track.hbm.xml is given below:

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

<hibernate-mapping>
   <class name="com.oreilly.hh.Track" table="TRACK">
      <meta attribute="class-description">
         Represents a single playable track in the music database.
         @author Vara Prasad Bokka (with help from Hibernate)
      </meta>
      
      <id name="id" type="int" column="TRACK_ID">
         <meta attribute="scope-set">protected</meta>
         <generator class="assigned"/>
      </id>
      
      <property name="title" type="string" not-null="true"/>
      
      <property name="filePath" type="string" not-null="true"/>
      
      <property name="playTime" type="time">
         <meta attribute="field-description">Playing time</meta>
      </property>
      
      <property name="added" type="date">
         <meta attribute="field-description">When the track was created</meta>
      </property>
      
      <property name="volume" type="short" not-null="true">
         <meta attribute="field-description">How loud to play the track</meta>
      </property>
      
   </class>
</hibernate-mapping>


My build.xml is given below:
Code:
<?xml version="1.0"?>
<project name="Harnessing Hibernate: The Developer's Notebook" default="db" basedir=".">
   
   <!-- Set up properties containing important project directories -->
   <property name="source.root" value="src"/>
   <property name="class.root" value="classes"/>
   <property name="lib.dir" value="lib"/>
   <property name="data.dir" value="data"/>
   
   <!-- Set up the class path for compilation and execution -->
   <path id="project.class.path">
      <!-- Include our own classes, of course -->
      <pathelement location="${class.root}" />
      <!-- Include jars in the project library directory -->
      <fileset dir="${lib.dir}">
         <include name="*.jar"/>
      </fileset>   
   </path>
   
   <target name="db" description="Runs HSQLDB database management UI
      against the database file--use when application is not running">
      
      <java classname="org.hsqldb.util.DatabaseManager" fork="yes">
         <classpath refid="project.class.path"/>
         <arg value="-driver"/>
         <arg value="org.hsqldb.jdbcDriver"/>
         <arg value="-url"/>
         <arg value="jdbc:hsqldb:${data.dir}/music"/>
         <arg value="-user"/>
         <arg value="sa"/>
      </java>
   </target>
      
   <!-- Generate the java code for all mapping files in our source tree -->
   <target name="codegen" description="Generate Java source from the O/R mapping files">
      <!-- Teach Ant how to use Hibernate's code generation tool -->
      <taskdef name="hbm2java"
             classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask"
             classpathref="project.class.path"/>
      
      <hbm2java output="${source.root}">
         <fileset dir="${source.root}">
            <include name="**/*.hbm.xml"/>
         </fileset>
      </hbm2java>
   </target>
   
   <!-- Create our runtime subdirectories and copy resources into them -->
   <target name="prepare" description="Sets up build structures">
      <mkdir dir="${class.root}"/>
      
      <!-- Copy our property files and O/R Mapping for use at runtime -->
      <copy todir="${class.root}">
         <fileset dir="${source.root}">
            <include name="**/*.properties"/>
            <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>
   
   <!-- Generate the schemas for all mapping files in our class tree -->
     <target name="schema" depends="compile"
             description="Generate DB schema from the O/R mapping files">

       <!-- Teach Ant how to 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.properties"
                     quiet="no" text="no" drop="no" delimiter=";">
         <fileset dir="${class.root}">
           <include name="**/*.hbm.xml"/>
         </fileset>
       </schemaexport>
     </target>
</project>


My hibernate.properties file is given below:
Code:
hibernate.dialect=net.sf.hibernate.dialect.HSQLDialect
hibernate.connection.driver_class=org.hsqldb.jdbcDriver
hibernate.connection.url=jdbc:hsqldb:data/music
hibernate.connection.username=sa
hibernate.connection.password=


My log4j.properties file is given below:
Code:
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### direct messages to file hibernate.log ###
#log4j.appender.file=org.apache.log4j.FileAppender
#log4j.appender.file.File=hibernate.log
#log4j.appender.file.layout=org.apache.log4j.PatternLayout
#log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### set log levels - for more verbose logging change 'info' to 'debug' ###

log4j.rootLogger=warn, stdout

log4j.logger.net.sf.hibernate=info

### log just the SQL
#log4j.logger.net.sf.hibernate.SQL=debug

### log JDBC bind parameters ###
log4j.logger.net.sf.hibernate.type=info

### log schema export/update ###
log4j.logger.net.sf.hibernate.tool.hbm2ddl=debug

### log cache activity ###
#log4j.logger.net.sf.hibernate.cache=debug

### enable the following line if you want to track down connection ###
### leakages when using DriverManagerConnectionProvider ###
#log4j.logger.net.sf.hibernate.connection.DriverManagerConnectionProvider=trace


When I run the build file with the target "schema", the following error has displayed:

Code:
Buildfile: C:\NOK\eclipse\workspace\hdnb\build.xml
prepare:
     [copy] Copying 3 files to C:\NOK\eclipse\workspace\hdnb\classes
compile:
    [javac] Compiling 2 source files to C:\NOK\eclipse\workspace\hdnb\classes
schema:
[schemaexport] log4j:WARN No appenders could be found for logger (net.sf.hibernate.cfg.Environment).
[schemaexport] log4j:WARN Please initialize the log4j system properly.
[schemaexport] drop table BOOK if exists;
[schemaexport] drop table TRACK if exists;
[schemaexport] create table BOOK (
[schemaexport] BOOK_ID integer not null,
[schemaexport] title varchar(255) not null,
[schemaexport] author varchar(255) not null,
[schemaexport] price float,
[schemaexport] publishDate date,
[schemaexport] primary key (BOOK_ID)
[schemaexport] );
[schemaexport] create table TRACK (
[schemaexport] TRACK_ID integer not null,
[schemaexport] title varchar(255) not null,
[schemaexport] filePath varchar(255) not null,
[schemaexport] playTime time,
[schemaexport] added date,
[schemaexport] volume smallint not null,
[schemaexport] primary key (TRACK_ID)
[schemaexport] );
BUILD SUCCESSFUL
Total time: 3 seconds


Here, the problems are given below:
1. It doesn't generate the database table.
2. Why it has given the above 2 warnings?

But it generates the music.script with the following information given below:
Code:
CREATE SCHEMA PUBLIC AUTHORIZATION DBA
CREATE USER SA PASSWORD ""
GRANT DBA TO SA
SET WRITE_DELAY 20


What might be the problem and what was the mistake that I did?

Thanks in advance!

Regards,
Vara Prasad Bokka.[/code]

_________________
Vara Prasad Bokka


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 8:47 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
configure log4j or some other logging supported by commons logging and you should be able to see it!

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