-->
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.  [ 6 posts ] 
Author Message
 Post subject: CREATE TABLE with SQLQuery in Hibernate 3.2.4
PostPosted: Mon Jul 02, 2007 5:21 pm 
Newbie

Joined: Tue May 22, 2007 9:53 am
Posts: 9
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Hello I'm working with Hibernate 3.2.4, and I'm working with some database issues that I have have implemented using it. The question is if I can perform tables creation with Hibernate so: "CREATE TABLE 'table-name' ('id-name' 'id-type', 'field1-name' "field1-type", ...)". Off course using SQLQuery. Is this possible to do with Hibernate? How?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 03, 2007 3:52 am 
Pro
Pro

Joined: Mon Jan 24, 2005 5:39 am
Posts: 216
Location: Germany
Hi,

you can Map the table/class in a *.hbm.xml.
Add this to you hibernate.cfg.xml
and set

Code:
<hibernate-configuration>

    <session-factory>
   
      <property name="hibernate.hbm2ddl.auto">create</property>


Hibernate then will create all tables which are referenced in you mapping.
Please read

[url]file:///C:/dev/hibernate-3.2.2.ga/hibernate-3.2/doc/reference/en/html/session-configuration.html[/url]

hope this helps.

_________________
dont forget to rate !


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 03, 2007 3:55 am 
Pro
Pro

Joined: Mon Jan 24, 2005 5:39 am
Posts: 216
Location: Germany
Hi,

you can Map the table/class in a *.hbm.xml.
Add this to you hibernate.cfg.xml
and set

Code:
<hibernate-configuration>

    <session-factory>
   
      <property name="hibernate.hbm2ddl.auto">create</property>


Hibernate then will create all tables which are referenced in you mapping.
Please read

[url]file:///C:/dev/hibernate-3.2.2.ga/hibernate-3.2/doc/reference/en/html/session-configuration.html[/url]

hope this helps.

_________________
dont forget to rate !


Top
 Profile  
 
 Post subject: Thanks so much but that's not exactly what I'm looking for
PostPosted: Mon Jul 09, 2007 6:39 pm 
Newbie

Joined: Tue May 22, 2007 9:53 am
Posts: 9
Thanks so much but that's not exactly what I'm looking for. The problem is that my application will perform dynamic tables creation. For example, my application receives information on what I want this new table to look like, number of fields or columns, datatypes for each of them, their names and all elements in a table creation. Then, I must have a method, that constructs the sentence dynamically with the provided information and executes it. So with each new calling to that method the sentence will be different. And I want to achieve the table creation with Hibernate, because I don't want this to be platform-dependant, and as I am also using Hibernate for other issues in the application, I tried to do it using SQLQuery. I realized that SQLQuery only works for SELECT sentences, so I am not able to do it and I will not perform dynamic inserts into these new tables (which is the next step). I just wanna know if it is not possible in any other way with Hibernate so I can stop trying and start to implement another solution for this issue. Thanks!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 10, 2007 8:39 am 
Regular
Regular

Joined: Mon Mar 26, 2007 12:38 am
Posts: 119
Hi,
>> I realized that SQLQuery only works for SELECT sentences
Further, HQL grammar clearly states that DDL is not supported.

statement
: ( updateStatement | deleteStatement | selectStatement | insertStatement)
;


Thus I THINK we cannot achieve it directly from Hibernate.

One option is to bank on underlying JDBC connection.
session.connection().createStatement().execute("my_ddl") ;
But, from your previous posts, it looks like you are not interested in this approach!!!

--------------------------------------------------
Rate the reply if you find it helpful


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 10, 2007 9:20 am 
Newbie

Joined: Tue May 22, 2007 9:53 am
Posts: 9
Yes you're right. Well it's not exactly that I'm not interested, my workteam has been given with that order, so I cannot use directly that solution you gave me. Although, we will continue using Hibernate for all the other things because it has proved to be a very good solution for data persistance. For this only issue I will try another thing. Thanks for your answers, all of them have been a good help!!!! Thank you all!!!!


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