• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is possible the DRY pinciple in the persistence Java world?

 
Iván Párraga
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I declare myself as a Java-phile but at the same time I'm also curious by nature and I've been flirting with some other languages in the last times. In particular I've been playing with Django and one thing I loved about it is the extensive use they do of the DRY principle.

DRY stands for "Don't Repeat Yourself" and it means that it should be just one canonical representation of the data model and you should write it just one time. They manage to implement this principle in its ORM.

Back to the Java world, this seems to be impossible: XML mapping files, POJOs, beans, database scripts... It's like to write the same again and again (an IT'S VERY BORING AND NO-PRODUCTIVE!!!). It's clear that with the new approaches (like using annotations) this things are getting better but in my humble opinion there is a lot of work to be done to get to the point whre other languages are today.

Of course this is a personal opinion, and perhaps I don't know the tools, techniques or libraries which allow us to have this in the Java world, so, finally, this is the question:

is it possible to have a persistence library/tool/technique in the Java world which accomplishes the DRY principle?

Cheers,

Iv�n
 
Lanny Gilbert
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure.. Hibernate uses it... Look here: http://www.hibernate.org/412.html
 
Iván Párraga
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers for the response!

Now the next step is to try to convince the developers to use it I'm a little bored to write the same again and again in the different projects I'm involved

Cheers,

Iv�n
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you're seeing this more and more, and these ideas are certainly embraced in modern JEE5 programming.

Following the DRY (Don't Repeat Yourself) principle, Hibernate Validator let's you express your domain constraints once (and only once) and ensure their compliance at various level of your system automatically.

Annotations are a very convenient and elegant way to specify invariant constraints on the domain model implementation, the persistent classes. Hibernate Validator comes bundled with a set of common validations (@NotNull, @Email, @Max, and so on), and you can build you own validation rules very easily.


And I think as we move past EJB2.x and into EJB 3.0, we're seeing less repetition, and more reuse of existing and working objects. Things are getting dryer.

-Cameron McKenzie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic