-->
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.  [ 12 posts ] 
Author Message
 Post subject: Schema Export in build script does not create table
PostPosted: Wed Aug 25, 2004 3:25 am 
Regular
Regular

Joined: Thu Aug 05, 2004 11:15 pm
Posts: 50
Hey I'm trying to just call the Schema Export tool to create the tables for me but it is not creating the tables.

I created a folder called practice2 and within it I have:

Here is my build file:

<?xml version="1.0"?>
<project name="test" default="compile" basedir=".">
<property name="src" value="."/>
<property name="build" value="build"/>


<target name="compile">
<!-- Compile the java code -->

<javac srcdir="${src}"/>
</target>

<target name="schemaexport">
<taskdef name="schemaexport"
classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask"
classpathref="class.path"/>

<schemaexport
properties="hibernate.properties"
quiet="no"
text="yes"
drop="no"
delimiter=";"
output="schema-export.sql">
<fileset dir="src">
<include name="**/*.hbm.xml"/>
</fileset>
</schemaexport>
</target>

</project>


Here is my Collection.hbm.xml file:

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

<hibernate-mapping>

<class name="Collection" table="COLLECTION3">
<id name="collectionID" type="integer" column="COLLECTIONID" unsaved-value="0">
<generator class="increment">
</generator>
</id>

<property name="name"/>

<property name="targetID"/>

<property name="parentID"/>

</class>

</hibernate-mapping>



Here is my Collection code:
// Collection.java

import java.io.*;
import java.util.Set;


public class Collection {

private Integer collectionID;
private String name;
private Integer targetID;
private Integer parentID;

public Collection() {
}

public Integer getCollectionID() {
return collectionID;
}

public void setCollectionID(Integer collectionID) {
this.collectionID = collectionID;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Integer getTargetID() {
return targetID;
}

public void setTargetID(Integer targetID) {
this.targetID = targetID;
}

public Integer getParentID() {
return parentID;
}

public void setParentID(Integer parentID) {
this.parentID = parentID;
}

}



Here is my hibernate.properties file that is in the hibernate-2.1/src directory. I am using MySQL database:

######################
### Query Language ###
######################

## define query language constants / function names

hibernate.query.substitutions true 1, false 0, yes 'Y', no 'N'



#################
### Platforms ###
#################

## JNDI Datasource

#hibernate.connection.datasource jdbc/test
#hibernate.connection.username db2
#hibernate.connection.password db2


## HypersonicSQL

#hibernate.dialect net.sf.hibernate.dialect.HSQLDialect
#hibernate.connection.driver_class org.hsqldb.jdbcDriver
#hibernate.connection.username sa
#hibernate.connection.password
#hibernate.connection.url jdbc:hsqldb:hsql://localhost
#hibernate.connection.url jdbc:hsqldb:test
#hibernate.connection.url jdbc:hsqldb:.


## PostgreSQL

#hibernate.dialect net.sf.hibernate.dialect.PostgreSQLDialect
#hibernate.connection.driver_class org.postgresql.Driver
#hibernate.connection.url jdbc:postgresql:template1
#hibernate.connection.username pg
#hibernate.connection.password
#hibernate.query.substitutions yes 'Y', no 'N'


## DB2

#hibernate.dialect net.sf.hibernate.dialect.DB2Dialect
#hibernate.connection.driver_class COM.ibm.db2.jdbc.app.DB2Driver
#hibernate.connection.url jdbc:db2:test
#hibernate.connection.username db2
#hibernate.connection.password db2


## DB2/400

#hibernate.dialect net.sf.hibernate.dialect.DB2400Dialect
#hibernate.connection.username user
#hibernate.connection.password password

## Native driver
#hibernate.connection.driver_class COM.ibm.db2.jdbc.app.DB2Driver
#hibernate.connection.url jdbc:db2://systemname

## Toolbox driver
#hibernate.connection.driver_class com.ibm.as400.access.AS400JDBCDriver
#hibernate.connection.url jdbc:as400://systemname


## MySQL

hibernate.dialect net.sf.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class org.gjt.mm.mysql.Driver
hibernate.connection.driver_class com.mysql.jdbc.Driver
hibernate.connection.url jdbc:mysql://localhost/test
hibernate.connection.username root
hibernate.connection.password password


## Oracle

#hibernate.dialect net.sf.hibernate.dialect.Oracle9Dialect
#hibernate.dialect net.sf.hibernate.dialect.OracleDialect
#hibernate.connection.driver_class oracle.jdbc.driver.OracleDriver
#hibernate.connection.username ora
#hibernate.connection.password ora
#hibernate.connection.url jdbc:oracle:thin:@localhost:1521:test


## Sybase

#hibernate.dialect net.sf.hibernate.dialect.SybaseDialect
#hibernate.connection.driver_class com.sybase.jdbc2.jdbc.SybDriver
#hibernate.connection.username sa
#hibernate.connection.password sasasa
#hibernate.connection.url jdbc:sybase:Tds:co3061835-a:5000/tempdb


## Mckoi SQL

#hibernate.dialect net.sf.hibernate.dialect.MckoiDialect
#hibernate.connection.driver_class com.mckoi.JDBCDriver
#hibernate.connection.url jdbc:mckoi:///
#hibernate.connection.url jdbc:mckoi:local://C:/mckoi1.00/db.conf
#hibernate.connection.username admin
#hibernate.connection.password nimda


## SAP DB

#hibernate.dialect net.sf.hibernate.dialect.SAPDBDialect
#hibernate.connection.driver_class com.sap.dbtech.jdbc.DriverSapDB
#hibernate.connection.url jdbc:sapdb://localhost/TST
#hibernate.connection.username TEST
#hibernate.connection.password TEST
#hibernate.query.substitutions yes 'Y', no 'N'


## MS SQL Server

#hibernate.dialect net.sf.hibernate.dialect.SQLServerDialect
#hibernate.connection.username sa
#hibernate.connection.password sa

## JSQL Driver
#hibernate.connection.driver_class com.jnetdirect.jsql.JSQLDriver
#hibernate.connection.url jdbc:JSQLConnect://1E1/test

## JTURBO Driver
#hibernate.connection.driver_class com.newatlanta.jturbo.driver.Driver
#hibernate.connection.url jdbc:JTurbo://1E1:1433/test

## WebLogic Driver
#hibernate.connection.driver_class weblogic.jdbc.mssqlserver4.Driver
#hibernate.connection.url jdbc:weblogic:mssqlserver4:1E1:1433

## Microsoft Driver (not recommended!)
#hibernate.connection.driver_class com.microsoft.jdbc.sqlserver.SQLServerDriver
#hibernate.connection.url jdbc:microsoft:sqlserver://1E1;DatabaseName=test;SelectMethod=cursor

## jTDS
#hibernate.connection.driver_class net.sourceforge.jtds.jdbc.Driver
#hibernate.connection.url jdbc:jtds:sqlserver://1E1/test;SelectMethod=cursor
#hibernate.jdbc.use_scrollable_resultset false

## Interbase

#hibernate.dialect net.sf.hibernate.dialect.InterbaseDialect
#hibernate.connection.username sysdba
#hibernate.connection.password masterkey

## DO NOT specify hibernate.connection.sqlDialect

## InterClient

#hibernate.connection.driver_class interbase.interclient.Driver
#hibernate.connection.url jdbc:interbase://localhost:3060/C:/firebird/test.gdb

## Pure Java

#hibernate.connection.driver_class org.firebirdsql.jdbc.FBDriver
#hibernate.connection.url jdbc:firebirdsql:localhost/3050:/firebird/test.gdb


## Pointbase

#hibernate.dialect net.sf.hibernate.dialect.PointbaseDialect
#hibernate.connection.driver_class com.pointbase.jdbc.jdbcUniversalDriver
#hibernate.connection.url jdbc:pointbase:embedded:sample
#hibernate.connection.username PBPUBLIC
#hibernate.connection.password PBPUBLIC



#################################
### Hibernate Connection Pool ###
#################################

hibernate.connection.pool_size 1



###########################
### C3P0 Connection Pool###
###########################

#hibernate.c3p0.max_size 2
#hibernate.c3p0.min_size 2
#hibernate.c3p0.timeout 5000
#hibernate.c3p0.max_statements 100
#hibernate.c3p0.idle_test_period 3000
#hibernate.c3p0.acquire_increment 2
##hibernate.c3p0.validate false



###################################
### Apache DBCP Connection Pool ###
###################################

## connection pool

#hibernate.dbcp.maxActive 100
#hibernate.dbcp.whenExhaustedAction 1
#hibernate.dbcp.maxWait 120000
#hibernate.dbcp.maxIdle 10

## prepared statement cache

#hibernate.dbcp.ps.maxActive 100
#hibernate.dbcp.ps.whenExhaustedAction 1
#hibernate.dbcp.ps.maxWait 120000
#hibernate.dbcp.ps.maxIdle 10

## optional query to validate pooled connections:

#hibernate.dbcp.validationQuery select 1 from dual
#hibernate.dbcp.testOnBorrow true
#hibernate.dbcp.testOnReturn false



##############################
### Proxool Connection Pool###
##############################

## Properties for external configuration of Proxool

hibernate.proxool.pool_alias pool1

## Only need one of the following

#hibernate.proxool.existing_pool true
#hibernate.proxool.xml proxool.xml
#hibernate.proxool.properties proxool.properties



#################################
### Plugin ConnectionProvider ###
#################################

## use a custom ConnectionProvider (if not set, Hibernate will choose a built-in ConnectionProvider using hueristics)

#hibernate.connection.provider_class net.sf.hibernate.connection.DriverManagerConnectionProvider
#hibernate.connection.provider_class net.sf.hibernate.connection.DatasourceConnectionProvider
#hibernate.connection.provider_class net.sf.hibernate.connection.C3P0ConnectionProvider
#hibernate.connection.provider_class net.sf.hibernate.connection.DBCPConnectionProvider
#hibernate.connection.provider_class net.sf.hibernate.connection.ProxoolConnectionProvider



#######################
### Transaction API ###
#######################

## the Transaction API abstracts application code from the underlying JTA or JDBC transactions

#hibernate.transaction.factory_class net.sf.hibernate.transaction.JTATransactionFactory
#hibernate.transaction.factory_class net.sf.hibernate.transaction.JDBCTransactionFactory


## to use JTATransactionFactory, Hibernate must be able to locate the UserTransaction in JNDI
## default is java:comp/UserTransaction
## you do NOT need this setting if you specify hibernate.transaction.manager_lookup_class

#jta.UserTransaction jta/usertransaction
#jta.UserTransaction javax.transaction.UserTransaction
#jta.UserTransaction UserTransaction


## to use JCS caching with JTA, Hibernate must be able to obtain the JTA TransactionManager

#hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.JBossTransactionManagerLookup
#hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.WeblogicTransactionManagerLookup
#hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.WebSphereTransactionManagerLookup
#hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.OrionTransactionManagerLookup
#hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.ResinTransactionManagerLookup



##############################
### Miscellaneous Settings ###
##############################

## print all generated SQL to the console

#hibernate.show_sql true


## auto schema export

#hibernate.hbm2ddl.auto create-drop
#hibernate.hbm2ddl.auto create
#hibernate.hbm2ddl.auto update


## specify a JDBC isolation level

#hibernate.connection.isolation 4


## set the JDBC fetch size

#hibernate.jdbc.fetch_size 25


## set the maximum JDBC 2 batch size (a nonzero value enables batching)

hibernate.jdbc.batch_size 0


## enable use of JDBC 2 scrollable ResultSets (specifying a Dialect will cause Hibernate to use a sensible default)

#hibernate.jdbc.use_scrollable_resultset true


## use streams when writing binary types to / from JDBC

hibernate.jdbc.use_streams_for_binary true


## use JDBC 3 PreparedStatement.getGeneratedKeys to get the identifier of an inserted row

#hibernate.jdbc.use_get_generated_keys true


## specify a default schema for unqualified tablenames

#hibernate.default_schema test


## use a custom stylesheet for XML generation (if not specified, hibernate-default.xslt will be used)

#hibernate.xml.output_stylesheet C:/Hibernate/net/sf/hibernate/hibernate-default.xslt


## enable outerjoin fetching (specifying a Dialect will cause Hibernate to use sensible default)

#hibernate.use_outer_join false


## set the maximum depth of the outer join fetch tree

hibernate.max_fetch_depth 1


## enable CGLIB reflection optimizer (enabled by default)

#hibernate.cglib.use_reflection_optimizer false



##########################
### Second-level Cache ###
##########################

## optimize chache for minimal "puts" instead of minimal "gets" (good for clustered cache)

#hibernate.cache.use_minimal_puts true


## set a prefix for cache region names

hibernate.cache.region_prefix hibernate.test


## enable the query cache

hibernate.cache.use_query_cache true


## choose a cache implementation

hibernate.cache.provider_class net.sf.ehcache.hibernate.Provider
#hibernate.cache.provider_class net.sf.hibernate.cache.EmptyCacheProvider
#hibernate.cache.provider_class net.sf.hibernate.cache.HashtableCacheProvider
#hibernate.cache.provider_class net.sf.hibernate.cache.TreeCacheProvider
#hibernate.cache.provider_class net.sf.hibernate.cache.OSCacheProvider
#hibernate.cache.provider_class net.sf.hibernate.cache.JCSCacheProvider
#hibernate.cache.provider_class net.sf.hibernate.cache.SwarmCacheProvider



############
### JNDI ###
############

## specify a JNDI name for the SessionFactory

#hibernate.session_factory_name hibernate/session_factory


## Hibernate uses JNDI to bind a name to a SessionFactory and to look up the JTA UserTransaction;
## if hibernate.jndi.* are not specified, Hibernate will use the default InitialContext() which
## is the best approach in an application server

#file system
#hibernate.jndi.class com.sun.jndi.fscontext.RefFSContextFactory
#hibernate.jndi.url file:/

#WebSphere
#hibernate.jndi.class com.ibm.websphere.naming.WsnInitialContextFactory
#hibernate.jndi.url iiop://localhost:900/



When I'm in the practice2 directory and I call ant, I get build successful and it compiles the Collection.java file and creates a class file. However it does not create a table in my test database. What am I doing wrong? Do I need to change or include anything more?

Thx,
Mush


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 25, 2004 3:33 am 
Regular
Regular

Joined: Thu Aug 05, 2004 2:27 am
Posts: 54
Location: South Africa
in your build file, switch text="yes" to text="false/no/off" and try again


Top
 Profile  
 
 Post subject: Still Doesn't work the Schema Export
PostPosted: Wed Aug 25, 2004 2:22 pm 
Regular
Regular

Joined: Thu Aug 05, 2004 11:15 pm
Posts: 50
I changed the text to "false/no/off" and it still doesn't create a table. Am I missing something really simple? All I've included in the folder was my Collection class, Collection.hbm.xml, and my build file.

Here is my build file again:

<?xml version="1.0"?>
<project name="test" default="compile" basedir=".">
<property name="src" value="."/>
<property name="build" value="build"/>


<target name="compile">
<!-- Compile the java code -->

<javac srcdir="${src}"/>
</target>

<target name="schemaexport">
<taskdef name="schemaexport"
classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask"
classpathref="class.path"/>

<schemaexport
properties="hibernate.properties"
quiet="no"
text="false/no/off"
drop="no"
delimiter=";"
output="schema-export.sql">
<fileset dir="src">
<include name="**/*.hbm.xml"/>
</fileset>
</schemaexport>
</target>
</project>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 25, 2004 2:29 pm 
Regular
Regular

Joined: Thu Aug 05, 2004 11:15 pm
Posts: 50
Maybe I didn't include a classpath thing in my tags in my build file so it is not reading the file? Any help appreciated.

Thx


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 26, 2004 2:54 am 
Regular
Regular

Joined: Thu Aug 05, 2004 2:27 am
Posts: 54
Location: South Africa
mush wrote:
Maybe I didn't include a classpath thing in my tags in my build file so it is not reading the file? Any help appreciated.

Thx


sorry I meant one of "false/no/off", all meaning the same thing.
so text="false" will do


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 26, 2004 4:24 am 
Regular
Regular

Joined: Thu Aug 05, 2004 11:15 pm
Posts: 50
I changed it to text="false" but it is still not working. Same thing, like it says build successful but no table created when I check my database. My build file is really simple, do I need to add anything to it? Or do I have to include any other files in my folder?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 26, 2004 5:13 am 
Regular
Regular

Joined: Thu Aug 05, 2004 2:27 am
Posts: 54
Location: South Africa
mush wrote:
I changed it to text="false" but it is still not working. Same thing, like it says build successful but no table created when I check my database. My build file is really simple, do I need to add anything to it? Or do I have to include any other files in my folder?


is that your entire build file? sorry I thought that was a snippet.
but I don't see a driver specified, amongst other things, how will you update the database?

here's a snippet from my build file, I found some tutorials which I modified to my needs, you can look on hibernate site to find them.


Code:

<!-- =================================================================== -->
   <!-- Create tables                                                       -->
   <!-- =================================================================== -->
   <target
      name="create-tables"
      depends="init-db, check-driver-present,panic-if-driver-not-present"
      description="Create tables"
   >
      <echo>Creating tables using URL ${database.url}</echo>
      <sql
         classpath="${database.driver.classpath}"
         driver="${database.driver}"
         url="${database.url}"
         userid="${database.userid}"
         password="${database.password}"
         src="${database.script.file}"
         print="true"
         output="result.txt"
      />
   </target>
   <target name="check-driver-present">
      <available file="${database.driver.file}" type="file" property="driver.present"/>
   </target>

   <target name="panic-if-driver-not-present" unless="driver.present">
      <fail>
      The JDBC driver you have specified by including one of the files in ${basedir}/cfg/database
      doesn't exist. You have to download this driver separately and put it in ${database.driver.file}
      Please make sure you're using a version that is equal or superior to the one we looked for.
      If you name the driver jar file differently, please update the database.driver.file property
      in the ${basedir}/cfg/database/xxx.xml file accordingly.
      </fail>
   </target>

<target name="init-db" depends="build" description="Creates the app database.">
        <taskdef classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask"
            classpathref="project.class.path" name="schemaexport"/>
        <schemaexport delimiter=";" drop="false" output="${database.script.file}"
            properties="cfg/hibernate.properties" quiet="true" text="false">           
            <fileset dir="${build.src}">
                <include name="**/*.hbm.xml"/>
            </fileset>           
        </schemaexport>
    </target>



Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 9:42 pm 
Regular
Regular

Joined: Thu Aug 05, 2004 11:15 pm
Posts: 50
Sometimes I get a "Content is not allowed in prolog. " error when i type ant into the command line. Do you happen to know what the prob might be?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 10:01 pm 
Regular
Regular

Joined: Thu Aug 05, 2004 11:15 pm
Posts: 50
So here is my new build script. Part of the code is taken from your code, like the create tables part (Heh I am not going to like use it for commercial needs). So at this point in my build script, all I want to do haha is create the table COLLECTION3 in the test database, as the database is specified in my hibernate.properties file in the src folder(I think that's where it is suppose to be).

So here is my build script but like it keeps on saying 'Content is not allowed in prolog.' when I type ant when I am in the practice2 folder which is in the hibernate-2.1 folder.

<project name="kenny" default="compile" basedir=".">
<property name="src" value="."/>
<property name="build" value="build"/>

<target name="init">
<mkdir dir="${build}"/>
</target>

<target name="compile" depends="init">
<!-- Compile the java code -->
<javac srcdir="${src}" destdir="${build}"/>
</target>




<!-- from an Ant build.xml -->
<target name="init-db">
<taskdef classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask" classpathref="project.class.path" name="schemaexport"/>
<schemaexport delimiter=";" drop="false" output="schema.sql" properties="config/hibernate.properties" quiet="false" text="false">
<fileset dir="${build.destdir}">
<include name="**/*.hbm.xml"/>
</fileset>
</schemaexport>
</target>


<target
name="create-tables"
depends="init-db"
description="Create tables"
>
<echo>Creating tables using URL ${database.url}</echo>
<sql
classpath="${database.driver.classpath}"
driver="${database.driver}"
url="${database.url}"
userid="${database.userid}"
password="${database.password}"
src="${database.script.file}"
print="true"
output="result.txt"
/>
</target>

</project>


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 28, 2004 2:04 pm 
Newbie

Joined: Sat Aug 28, 2004 1:14 pm
Posts: 2
The problem maybe in your map files.
try to uncomment lines as below, and run TestCase.
Code:
#hibernate.show_sql true
#hibernate.hbm2ddl.auto update

And then, you will see all the create/alter sql, and create all the tables that was defined in map files, if your map files is extract correctly.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 01, 2004 8:52 pm 
Regular
Regular

Joined: Thu Aug 05, 2004 11:15 pm
Posts: 50
what do u mean by run TestCase?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 2:50 pm 
Newbie

Joined: Wed Nov 19, 2003 3:00 am
Posts: 7
Location: Madison, Wisconsin, USA
This is probably due to a change in Hypersonic's behavior starting with version 1.7.2. In a nutshell, old versions would automatically shut down the database as soon as there were no more connections to it. The new versions don't shut down unless given an explicit shutdown command, and hbm2ddl does not issue that shutdown command, so Hypersonic never flushes the changes to disk before the JVM gets shut down. Hence, your schema is never written to disk.

If you are using Hypersonic 1.8 or later you can work around this by requesting the old automatic shutdown behavior. Hibernate will enable this if you define hibernate.connection.shutdown=true in your properties or XML file.


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