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