-->
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: Newbie question: model-first or database-first ?
PostPosted: Thu Jan 27, 2011 11:35 pm 
Newbie

Joined: Thu Jan 27, 2011 11:22 pm
Posts: 4
Hi,

I'm new to NHibernate. I'm working on a relatively small project that I think would be good to get my feet wet with NHibernate. I would expect it to have 10 tables or so. I am using VS2010/C#/SQL Server 2008.

I've read some articles that recommend a model-first approach, whereas others recommend a database-first approach. I can't figure out which is best. (I do see one benefit with the database-first approach: I can use a code generator to generate my business object/data layers.)

Is this a subjective decision based on experience, or is there an objective way I can decide which is the more suitable approach?

Thanks.


Top
 Profile  
 
 Post subject: Re: Newbie question: model-first or database-first ?
PostPosted: Mon Jan 31, 2011 3:27 pm 
Newbie

Joined: Mon Jan 31, 2011 3:06 pm
Posts: 2
Hi

Both approaches have pros and cons as always is the case. It is probably a good idea to mix both together.

You mentioned code generation as a benefit of databas-first. But similarily you can generate database schema using your model and mapping files.
Considering the effort required I think that model-first approach is better in this regard. You write your model as you normally would. Map using hbm.xml, fluent nhibernate, mapping attributes, castle activerecord or whatever means you can come up with and Schema Export creates the schema for you. On the other hand, if you start with database schema it is easy to mess up naming convention and either end up with much more mapping to write or an ugly ugly model. I must admin though, that I have never used any code generators you mention, so I may underestimate them.

Other than that one may try to compare the final database performance. Model-first approach probably ends up with more associations and inheritance and thus more joined tables, which could affect how your application performs. Designing the database schema first inhibits creating too many tables but it is also not object-oriented so the object model outcome of both approaches could be different, which again makes the two harder to compare.

Other than the above, what comes to my mind is using the full potential of a relational database has. I have noticed, that designing model first makes me forget about views, triggers and stored procedures for example. And I certainly never forget about them when designing database-first.

Not sure wht you can make out of it. The choice is hard but it's your to make ;).

Personally I prefer model-first approach, because I find it easier to update the schame, as model changes. And if you would choose this path, try not to neglect what your server of choice has to offer.

Regards
Tomasz


Top
 Profile  
 
 Post subject: Re: Newbie question: model-first or database-first ?
PostPosted: Wed Feb 02, 2011 5:37 pm 
Newbie

Joined: Thu Jan 27, 2011 11:22 pm
Posts: 4
Tomasz,

Thanks so much -- great advice. After reading this, along with some other articles, I have decided to try model-first. This is a relatively small project, and there is no existing database, so it's a good opportunity to try the model-first approach.

-l


Top
 Profile  
 
 Post subject: Re: Newbie question: model-first or database-first ?
PostPosted: Wed Feb 02, 2011 7:32 pm 
Newbie

Joined: Mon Jan 31, 2011 3:06 pm
Posts: 2
Right it is.

And honestly. You can read all books, posts and articles you want. But you won't really know your answer until, you've tried both.

Do give database-first a try some other time, and decide for yourself then. Or just have some exercise with made-up projects. That is always a good idea to experiment, isn't it? :)

Good luck


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.