views:

39

answers:

2

I'm developing a JEE application (JSF + Richfaces + Oracle 10g), and i wanted to use JPA.

But in the end, i didn't see any advantages of using it, because it's going to complexify my code.

I found that calling my procedures (stored procedures in my orale DB) is better than using JPA (because i can, for example, change some lines in those procedures without the need to re'compile my "WAR" project every time i have some error + i can use PL/SQL which helps me a lot)

So, i wanted to ask you people, when to use JPA ?

Isn't making your own queries (you can choose the right ordering for you selects, the columns that you want to select, and not all the columns: because of ORM and the fact that your entities attributes are mapped to the columns of your table, and that oblige you to select all the attributes present in your entity,....)

Is it my method that i used (stored function)

+1  A: 

You can define what fields are retrieved in a query, using JPA. Why is the complexity of your code going up with use of JPA ? You state no example. Before you'd have to do messy JDBC, and now you just call "em.persist(obj)" ... is that really more complex.

You ought to be thinking in terms of what relations there are between objects (if any) and that be the determiner on whether you need an ORM

+2  A: 

But in the end, i didn't see any advantages of using it, because it's going to complexify my code.

This might be subjective but, personally, I find JDBC typically more verbose, harder to maintain and thus somehow more complex. With an ORM like JPA, you don't have to write all the CRUD queries, you don't have to handle the mapping of query results to objects, you don't have to handle the low level stuff yourself, etc.

I found that calling my procedures (stored procedures in my orale DB) is better than using JPA (because i can, for example, change some lines in those procedures without the need to re'compile my "WAR" project every time i have some error + I can use PL/SQL which helps me a lot)

This is totally dependent on your definition of "better". In your case, you might prefer SP because of your development workflow (I don't run my code in container to setup the persistence part) and because you are comfortable with PL/SQL. But again, personally, I don't find SP "better":

  • I don't really enjoy hand writing SQL queries for everything
  • I find that SP are harder to test, debug, maintain
  • I find that SP are bad for code reuse
  • I find that SP lock you in (I consider this as a disadvantage)
  • I tend to find systems build around SP harder to scale

Read also Who Needs Stored Procedures, Anyways? (amongst other resource) for more opinions.

So, I wanted to ask you people, when to use JPA ?

When you want to speed-up development, to focus on implementing business code instead of plumbing. And of course, when appropriate.

Isn't making your own queries (...)

Did you identify a particular performance problem? Or are you just assuming there will be a problem. To my experience, retrieving more columns than required is most of time not an issue. And if it becomes an issue, there are solutions.

Pascal Thivent
i'll give it a try because like you said, i'm just assuming. thank you for your answer.
mohamida
+1, (for "Who Needs Stored Procedures" at least)
Bozho
hah, seems like my vote was not cast yestarday. So here it is now. And congrats for the 100k rep :)
Bozho
@Bozho Thanks Bozho. Next one now ;)
Pascal Thivent