-->
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.  [ 4 posts ] 
Author Message
 Post subject: Executing arbitrary SQL (including CREATE TABLE)
PostPosted: Fri Dec 30, 2011 2:09 pm 
Newbie

Joined: Fri Dec 23, 2011 7:40 pm
Posts: 12
I'm looking for a way to programmatically execute arbitrary SQL commands against my DB.
Query.createNativeQuery() doesn't work for things like CREATE TABLE.

Doing LOTS of searching, it looks like I can use Session.doWork().
The only problem is that I haven't been able to figure out how to get a Session object.
My code currently just does:
mEMF = Persistence.createEntityManagerFactory("WorkingDB", props);
to get things working, and uses mEMF.createEntityManager() as needed.

So, how do I get a Session to my database?


Top
 Profile  
 
 Post subject: Re: Executing arbitrary SQL (including CREATE TABLE)
PostPosted: Fri Dec 30, 2011 2:19 pm 
Newbie

Joined: Fri Dec 23, 2011 7:40 pm
Posts: 12
using the deprecated Configuration.buildSesionFactory() seems to show that doWork won't work.
I get "use lacks privilege or object not found" for all the CREATE TABLE statements.

So, what OTHER technique is there for this?


Top
 Profile  
 
 Post subject: Re: Executing arbitrary SQL (including CREATE TABLE)
PostPosted: Fri Dec 30, 2011 3:20 pm 
Newbie

Joined: Wed Nov 10, 2010 4:24 pm
Posts: 6
Use createSQLQuery:

http://docs.jboss.org/hibernate/core/4. ... -nativesql


Top
 Profile  
 
 Post subject: Re: Executing arbitrary SQL (including CREATE TABLE)
PostPosted: Fri Dec 30, 2011 4:04 pm 
Newbie

Joined: Fri Dec 23, 2011 7:40 pm
Posts: 12
Ok, tried createSQLQuery().

Turns out that it's my call to buildSessionFactory() that is puking.

SessionFactory sf = new Configuration().configure().buildSessionFactory();

results in a HibernateException /hibernate.cfg.xml not found.
Well, since the system is using a persistence.xml, that makes sense.

So, HOW DO I GET A SESSIONFACTORY!!!


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