-->
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.  [ 7 posts ] 
Author Message
 Post subject: Table creation in Hibernate
PostPosted: Tue Jan 06, 2009 9:36 am 
Newbie

Joined: Tue Jan 06, 2009 9:33 am
Posts: 7
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 Jan 06, 2009 9:38 am 
Regular
Regular

Joined: Wed Oct 15, 2008 6:59 am
Posts: 103
Location: Chennai
you can Map the table/class in a *.hbm.xml.
Add this to you hibernate.cfg.xml

and set

<hibernate-configuration>

<session-factory>

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


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

_________________
If u feel it will help you, don't forget to rate me....


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 06, 2009 9:40 am 
Newbie

Joined: Tue Jan 06, 2009 9:33 am
Posts: 7
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 Jan 06, 2009 9:42 am 
Regular
Regular

Joined: Wed Oct 15, 2008 6:59 am
Posts: 103
Location: Chennai
One option is to bank on underlying JDBC connection.
session.connection().createStatement().execute("my_ddl") ;

_________________
If u feel it will help you, don't forget to rate me....


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 06, 2009 9:43 am 
Newbie

Joined: Tue Jan 06, 2009 9:33 am
Posts: 7
other than using JDBC code, we have anything alternate for that ...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 06, 2009 9:45 am 
Regular
Regular

Joined: Wed Oct 15, 2008 6:59 am
Posts: 103
Location: Chennai
if u use JDBC code, u will lose ur abstraction of hibernate. my option u will go with hbm2ddl.auto property.

_________________
If u feel it will help you, don't forget to rate me....


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 06, 2009 9:46 am 
Newbie

Joined: Tue Jan 06, 2009 9:33 am
Posts: 7
Thank you for your instant reply friend


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