-->
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.  [ 1 post ] 
Author Message
 Post subject: Ant/hbm2ddl to Generate DB Tables With Annotations
PostPosted: Thu May 14, 2009 3:12 pm 
Newbie

Joined: Thu May 14, 2009 3:02 pm
Posts: 1
I'm currently learning about Hibernate so please forgive the noob question. I'm attempting to get Hibernate to generate SQL creation scripts and execute the code against the database. I've done this using the "SchemaExportTast" but am having no luck with hbm2ddl.

I can get it to create the required SQL and export it to a file but am unable to get it to execute against an existing mysql database.

Any help would be greatly appreciated.

Hibernate.cfg.xml:
<?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">

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/librarydemo</property>
<property name="connection.username">root</property>
<property name="connection.password">shiva98</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<property name="show_sql">true</property>

<!-- Classes -->
<mapping class="com.metaarchit.bookshop.Book" />
</session-factory>
</hibernate-configuration>

Relevant Ant Task:
<target name="schemaexport">
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="hibernate.schemaexport.classpath" />

<hibernatetool destdir="${basedir}/dbscripts/generated">
<annotationconfiguration configurationfile =
"${resources.dir}/hibernate.cfg.xml"/>
<hbm2ddl
export="true"
drop="true"
create="true"
format="true"/>
</hibernatetool>
</target>

Once again, I can generate the expected SQL code and export it to a file but am unable to get it to execute directly against the database for development/texting purposes. I "know" this is going to be something obvious but I've run through all the examples I can find and it seems that this "should" work using the hibernate.cfg.xml file and hbm2ddl.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.