-->
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: Hibernate 4.x - Accessing Hibernate Configuration from JPA
PostPosted: Wed Feb 29, 2012 6:52 pm 
Newbie

Joined: Thu Jul 29, 2004 8:31 am
Posts: 7
Location: Brazil
At Hibernate 4.1 developer guide section 3.9 (Accessing Hibernate APIs from JPA) is explaind how to get Session and SessionImplementor using JPA API. I'm having a lot of problems trying to use Hibernate Tools and Ant Schema Export Task, since I use JPA persistence.xml configuration file.

I'm trying to generate schema programatically, so I need access to Hibernate Configuration object. I could be done using Ejb3Configuration, but it's deprecated. How to get Hibernate Configuration using JPA?

_________________
Daniel Brasil
CEO Hive.log


Top
 Profile  
 
 Post subject: Re: Hibernate 4.x - Accessing Hibernate Configuration from JPA
PostPosted: Thu Mar 01, 2012 3:03 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Hi Daniel,

unfortunately there's no official Hibernate4-conform Hibernate-Tools available so far,
thus there is also no Ant Schema Export Task working for the moment.

You can generate the schema by launching your application with a persistence.xml
specifying property:

Code:
<property name="hibernate.hbm2ddl.auto" value="create"></property>


Top
 Profile  
 
 Post subject: Re: Hibernate 4.x - Accessing Hibernate Configuration from JPA
PostPosted: Thu Mar 08, 2012 6:44 pm 
Newbie

Joined: Thu Jul 29, 2004 8:31 am
Posts: 7
Location: Brazil
Thank's.

I've tried to use Ant Tasks and Maven Plugin but i've no success. So I'm using EJB3Configuration deprecated class.

Code:
public class SchemaExportUtils {
   public static void export(String persistenceUnit, String exportFileName) {
      Ejb3Configuration cfg = new Ejb3Configuration();
      Ejb3Configuration configured = cfg.configure(persistenceUnit,
            new HashMap<String, Object>());
      Configuration hbmcfg = cfg.getHibernateConfiguration();
      SchemaExport schemaExport = new SchemaExport(hbmcfg);
      schemaExport.setOutputFile(exportFileName);
      schemaExport.setFormat(false);
      schemaExport.setDelimiter(";");
      schemaExport.drop(true, true);
      schemaExport.create(true, true);
   }
}

_________________
Daniel Brasil
CEO Hive.log


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.