db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmclea...@comcast.net
Subject Re: recommended practices? dealing with the database-application divide
Date Wed, 06 Jun 2007 17:06:12 GMT
This is the kind of thing where ORM (object-relational mapping) can be very useful.

I use Hibernate (www.hibernate.org) but there are a number of other solutions and you have
to find one that best meets the needs of your project.

Donald

 -------------- Original message ----------------------
From: "Ryan Bobko" <ryan@ostrich-emulators.com>
> Hi Folks,
> This is something I seem to struggle with every time I write a new db
> application. I feel like I design the database logically, but somewhere
> in the application code, I always seem to define constants that directly
> mirror what's in my database. I'm interested in how other people deal
> with this, and/or if there's something I should be doing to avoid the
> situation.
> 
> For example, suppose I have a two tables for dealing with users:
> 
> create table user( id int primary key, name varchar(20), level int );
> create table privilege( id int primary key, desc text );
> insert into privilege( id, desc ) values( 0, 'user' );
> insert into privilege( id, desc ) values( 1, 'adminstrator' );
> 
> Then in my code, I can get users and their level, but somewhere I need
> to define what the levels are. I seem to have statements like:
> 
> public static final int ADMIN=1;
> if( ADMIN==user.level ){...}
> 
> Obviously, this is a simple case where I could just as easily add an
> "isAdmin" column to the table, but what if I had ten different levels?
> 
> One of the things I like about using the database is that I can change
> values easily, but that is of no value when the app is so tightly
> coupled with the database. Any solutions out there?

Mime
View raw message