-->
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.  [ 8 posts ] 
Author Message
 Post subject: create tables with sql or hibernate
PostPosted: Tue Sep 14, 2010 7:42 am 
Beginner
Beginner

Joined: Thu Jun 17, 2010 7:36 am
Posts: 26
Hello,

Im new to Hibernate and Im working on a small webapplication using Spring and Hibernate.
Until now, I created my tables using MySQL Server 5.1. with the normal create table commands manually.
I used then hibernate in my project to get the data from my database as objects and to use them.
everything works fine.

now Im wondering if it would make more sense to generate the whole database using hibernate. I mean that from the mappingfiles and the other xml files the database will be generated automatically and that I do not create it manually.

So first I would like to know what the recommended way to use hibernate is: generate tables manually and use them then per hibernate or generate the whole database using hibernate

my second question is: I configured the dependencies between my tables using the create tables commands. I used primary keys, foreign keys, on delete cascade..... and so on. everything works fine.
my hibernatemappingfiles just represtents the single tables and their primary keys. Ive nothing specified there about any dependencies, .. foreign keys and so on. is this a mistake of mine?

I would be very grateful for an answer!
thanks!


Top
 Profile  
 
 Post subject: Re: create tables with sql or hibernate
PostPosted: Tue Sep 14, 2010 8:17 am 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
hi dude,

USe "<property name="hbm2ddl.auto">create</property>"
in your cfg .xml

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


Top
 Profile  
 
 Post subject: Re: create tables with sql or hibernate
PostPosted: Tue Sep 14, 2010 8:55 am 
Beginner
Beginner

Joined: Thu Jun 17, 2010 7:36 am
Posts: 26
hello,
thanks for your answer. I know that this line is resposible for hibernate to generate the database automatically. But this is not the answer to my questions :-(


Top
 Profile  
 
 Post subject: Re: create tables with sql or hibernate
PostPosted: Thu Sep 16, 2010 7:41 am 
Beginner
Beginner

Joined: Thu Jun 17, 2010 7:36 am
Posts: 26
please answer my newbie question! :-)


Top
 Profile  
 
 Post subject: Re: create tables with sql or hibernate
PostPosted: Mon Sep 20, 2010 6:33 am 
Beginner
Beginner

Joined: Thu Jun 17, 2010 7:36 am
Posts: 26
please... Im simply really new.


Top
 Profile  
 
 Post subject: Re: create tables with sql or hibernate
PostPosted: Mon Sep 20, 2010 6:49 am 
Senior
Senior

Joined: Tue Oct 28, 2008 10:39 am
Posts: 196
danold wrote:
please... Im simply really new.


As a developer I prefer tables to be generated by Hibernate, because it's easier to change your model. But...

- I would never ever do that in a production environment
- there are cases where you simply cannot generate tables everytime. (e.g. if you have some tables with static data and cannot load them everytime your app starts)

May the database user your app runs as isn't allowed to create tables. Or if you are developing in a team. You cannot create tables when you want to...

So, it depends.


Top
 Profile  
 
 Post subject: Re: create tables with sql or hibernate
PostPosted: Tue Sep 21, 2010 7:14 am 
Beginner
Beginner

Joined: Thu Jun 17, 2010 7:36 am
Posts: 26
first thanks for your answer. I try to understand it so lets imagine I would be in a production environment:

I think then it is the best way to write the database schema by myself with the create tables commands.
I also write the hibernate configuration by myself. Its possible to create then the java beans automatically, which I think is useful. (I read so)

I check my hibernate configuration this way then: I generate a Schema Creation Script automatically and compare it with my selfwritten database schema.

If I make changes then in my database, I change it manually in the server. Then I change the hibernate configuration manually too. I can recreate then my java beans.

If Im only developing I can create the database schema with hibernate, because its easy


what do you think about that?
Thank you :-)


Top
 Profile  
 
 Post subject: Re: create tables with sql or hibernate
PostPosted: Wed Sep 22, 2010 10:16 am 
Beginner
Beginner

Joined: Thu Jun 17, 2010 7:36 am
Posts: 26
I thought about this again and I changed my opinion.

Its so exhausting to generate all the mapping files by oneself. You can make mistakes and so on. So, no matter where, I guess its advisable to write the database schema and then create the mapping files automatically.

If I want to create then my database automatically on restart, I can think about it. As you said, it depends on the situation, that is now clear to me.

Unfortunately by trying to create the reverse engineering file (to get the hibernate mapping files from my database) I get this errormessage:

the database drivers are not added to the project classpath. go to project properties and add database library
I posted the problem in another topic in this forum, maybe someone can help me....?


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