-->
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.  [ 3 posts ] 
Author Message
 Post subject: Programatic Schema Export with Hibernate and EJB3
PostPosted: Mon Jun 04, 2007 4:32 pm 
Newbie

Joined: Mon Jun 04, 2007 4:10 pm
Posts: 1
Location: Florida
I am developing J2SE Application with Hibernate and HSQL database and I want db schema to be created programatically.

I following EJB3 - JPA approach and using persistence.xml as show below.


Code:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
    http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
   version="1.0">

   <persistence-unit name="astrosoft" transaction-type="RESOURCE_LOCAL">

       <provider>org.hibernate.ejb.HibernatePersistence</provider>
       
       
      <properties>
          <!-- Scan for annotated classes and Hibernate mapping XML files -->
          <property name="hibernate.archive.autodetection" value="class, hbm"/>

          <!-- SQL stdout logging -->
          <property name="hibernate.show_sql" value="true"/>
          <property name="hibernate.format_sql" value="true"/>
          <property name="use_sql_comments" value="true"/>
         

          <property name="hibernate.connection.driver_class"
                    value="org.hsqldb.jdbcDriver"/>
          <property name="hibernate.connection.url"
                    value="jdbc:hsqldb:file:db/astrodb;hsqldb.default_table_type=cached"/>                   
          <!-- <property name="hibernate.connection.url"
                    value="jdbc:hsqldb:hsql://localhost"/> -->
          <property name="hibernate.connection.username"
                    value="sa"/>
                   
          <property name="hibernate.connection.shutdown"
                    value="true"/>                   

          <property name="hibernate.c3p0.min_size"
                    value="5"/>
          <property name="hibernate.c3p0.max_size"
                    value="20"/>
          <property name="hibernate.c3p0.timeout"
                    value="300"/>
          <property name="hibernate.c3p0.max_statements"
                    value="50"/>
          <property name="hibernate.c3p0.idle_test_period"
                    value="3000"/>

          <property name="hibernate.dialect"
                    value="org.hibernate.dialect.HSQLDialect"/>
                   
          <!-- <property name="hibernate.hbm2ddl.auto" value="create" />  -->

      </properties>
   </persistence-unit>

</persistence>


To Use SchemaExport API, I need hibernate configuration, so I am trying to get hibernate cfg out of EJB 3 configuration. This is what I tried..

Code:

Ejb3Configuration cfg = new Ejb3Configuration().configure("/META-INF/persistence.xml");
Configuration hbmcfg = cfg.getHibernateConfiguration();
SchemaExport schemaExport = new SchemaExport(hbmcfg);
schemaExport.create(true, true);



But I am getting following error:


SEVERE: Error parsing XML: /META-INF/persistence.xml(1) Document is invalid: no grammar found.
Jun 4, 2007 4:24:43 PM org.hibernate.util.XMLHelper$ErrorLogger error
SEVERE: Error parsing XML: /META-INF/persistence.xml(1) Document root element "persistence", must match DOCTYPE root "null".


Please help me in knowing right way of exporting schema using EJB3/hibernate. My basic requirement is tables to be created automatically only if they does not exist, Please let me know if there are better way of doing it...


Any help would be very much appreciated..

Thanks,
Raja.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 16, 2007 9:35 pm 
Newbie

Joined: Sat Jun 16, 2007 9:34 pm
Posts: 1
I too am interested in the outcome of this question. Does anyone have an answer?


Top
 Profile  
 
 Post subject: Use the configure(string, map) method
PostPosted: Thu Jun 28, 2007 8:08 pm 
Newbie

Joined: Thu Jun 28, 2007 7:57 pm
Posts: 1
Location: Sydney, Australia
The configure(string) method you're calling takes a hibernate configuration file, not a persistence.xml file. Use the variant that accepts the name of a persistence unit instead.

Code:
Ejb3Configuration cfg = new Ejb3Configuration().configure("PersistenceUnitName", new Properties());
Configuration config = cfg.getHibernateConfiguration();

Dialect dialect = Dialect.getDialect(config.getProperties());
String[] createSql = config.generateSchemaCreationScript(dialect);


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.