Live data from Hacker News

Build RESTful web services with Java technology

ibm.com

11–20 of 30 posts

Re: Build RESTful web services with Java technology

#11
post #2

Building REST services with JAX-RS is truly pretty smooth and quick (I've been using Jersey not Wink though). One thing I don't ever recommend is using JPA based libraries (Hibernate, EclipseLink, whatever). Run screaming away from that spec as fast as you possibly can. There are much better options for ORMs in Java that don't have the session management headache and endless string of gotchas that is JPA. Ebean is my…

I'm using JPA with Spring Data JPA and I don't see a reason for avoiding it.

Though, I haven't taken a look and try at Ebean, and I will these days.

Re: Build RESTful web services with Java technology

#12
post #7

Earlier quoted context omitted.

Ah, I'm not the only one who thinks ORMs suck! That's why I love the latest development in the Scala community towards a non-ORM solution for persistence: Slick ( http://slick.typesafe.com ) and Play! Anorm ( http://www.playframework.org/documentation/2.0/ScalaAnorm )

I don't hate ORMs, but I hate when they are too intrusive. What I like about Ebean is that it was designed to only handle the simple stuff "ORMish" and provide a very smooth and easy breakdown to raw SQL so you get the best of both worlds. I also love "autotune", it tracks your call stack for queries and after it has enough statistics it'll start only fetching the fields that you actually ended up using. So if you ha…

I didn't quite understand it. From your example, it looks like ORM layer knows about 'pages', which are in views. Isn't it against clean separation of concerns?

Re: Build RESTful web services with Java technology

#13
post #4
post #2

Building REST services with JAX-RS is truly pretty smooth and quick (I've been using Jersey not Wink though). One thing I don't ever recommend is using JPA based libraries (Hibernate, EclipseLink, whatever). Run screaming away from that spec as fast as you possibly can. There are much better options for ORMs in Java that don't have the session management headache and endless string of gotchas that is JPA. Ebean is my…

Thanks a lot for the pointers. I have been looking for a good java framework to learn. I will be more than happy to settle with this 90% you quoted. They look simple enough to understand in a couple of days without wrestling with tons of XML config files.

Well. I know what you mean (XML hell). However to some degree doing config stuff in files and not in the code really makes sense...

However Spring using JSON as configuration format would be awesome :)

Re: Build RESTful web services with Java technology

#14
post #13
post #4

Earlier quoted context omitted.

Thanks a lot for the pointers. I have been looking for a good java framework to learn. I will be more than happy to settle with this 90% you quoted. They look simple enough to understand in a couple of days without wrestling with tons of XML config files.

Well. I know what you mean (XML hell). However to some degree doing config stuff in files and not in the code really makes sense... However Spring using JSON as configuration format would be awesome :)

You don't need JSON configuration even if it was existing.

You can use annotation based configuration (meaning Java classes with annotations like @Configuration, @EnableWebMvc etc..) for > 90% of the configuration cases:

http://blog.springsource.org/2011/06/10/spring-3-1-m2-config...

Re: Build RESTful web services with Java technology

#15
post #2

Building REST services with JAX-RS is truly pretty smooth and quick (I've been using Jersey not Wink though). One thing I don't ever recommend is using JPA based libraries (Hibernate, EclipseLink, whatever). Run screaming away from that spec as fast as you possibly can. There are much better options for ORMs in Java that don't have the session management headache and endless string of gotchas that is JPA. Ebean is my…

I'm using JPA with Spring Data JPA and I don't see a reason for avoiding it. Though, I haven't taken a look and try at Ebean, and I will these days.

JPA does have some gotchas and the learning curve is a little bit steep (not too steep, but just a wee bit).

You do need to know how JPA works internally a little bit (e.g.: EntityManager actually cache your objects unless you tell it specifically to "flush").

Re: Build RESTful web services with Java technology

#16
post #13

Earlier quoted context omitted.

Well. I know what you mean (XML hell). However to some degree doing config stuff in files and not in the code really makes sense... However Spring using JSON as configuration format would be awesome :)

You don't need JSON configuration even if it was existing. You can use annotation based configuration (meaning Java classes with annotations like @Configuration, @EnableWebMvc etc..) for > 90% of the configuration cases: http://blog.springsource.org/2011/06/10/spring-3-1-m2-config...

I prefer plain files instead of annotations. Just wish the non-readability of XML would go away with less bloated format (which other frameworks did with JSON).

Re: Build RESTful web services with Java technology

#17
post #4
post #2

Building REST services with JAX-RS is truly pretty smooth and quick (I've been using Jersey not Wink though). One thing I don't ever recommend is using JPA based libraries (Hibernate, EclipseLink, whatever). Run screaming away from that spec as fast as you possibly can. There are much better options for ORMs in Java that don't have the session management headache and endless string of gotchas that is JPA. Ebean is my…

Thanks a lot for the pointers. I have been looking for a good java framework to learn. I will be more than happy to settle with this 90% you quoted. They look simple enough to understand in a couple of days without wrestling with tons of XML config files.

If you're looking to write a backend service using Java, I would take a serious look at dropwizard http://dropwizard.codahale.com/

The get started page is not that long, and you should be able to kill it in a few hours. At the minimum you get http requests routed to methods and restful json parsed for you automatically. If you want, you can add optional configuration, metrics, healthcheck, logging, db access, views etc.

Re: Build RESTful web services with Java technology

#18
post #7

Earlier quoted context omitted.

I don't hate ORMs, but I hate when they are too intrusive. What I like about Ebean is that it was designed to only handle the simple stuff "ORMish" and provide a very smooth and easy breakdown to raw SQL so you get the best of both worlds. I also love "autotune", it tracks your call stack for queries and after it has enough statistics it'll start only fetching the fields that you actually ended up using. So if you ha…

I didn't quite understand it. From your example, it looks like ORM layer knows about 'pages', which are in views. Isn't it against clean separation of concerns?

It doesn't know about pages, it knows about the stack trace that resulted in a query being generated, e.g. it know that a specific method in the ProductController called a specific method in the ProductService, etc, leading to a query being generated.

It also know which fields of the object it returned were accessed prior to going out of scope and more importantly, which fields were never accessed. With those two bits of information gathered over many calls it can figure which fields are actually worth fetching from the database and which should be left off and fetched lazily in the odd case that they are needed.

Re: Build RESTful web services with Java technology

#19

Earlier quoted context omitted.

I'm using JPA with Spring Data JPA and I don't see a reason for avoiding it. Though, I haven't taken a look and try at Ebean, and I will these days.

JPA does have some gotchas and the learning curve is a little bit steep (not too steep, but just a wee bit). You do need to know how JPA works internally a little bit (e.g.: EntityManager actually cache your objects unless you tell it specifically to "flush").

My biggest problems with JPA:

1) CriteriaBuilder API is the worst API I've ever seen. I've never seen an API that turns a simple task into more lines of code than this monstrosity. I can't imagine many people use this thing, instead they use JPQL losing type safety in the process.

2) JPQL is still wildly verbose and very difficult to intertwine with native SQL. As an example try to generate something like "SELECT * FROM `order` o ORDER BY RAND() LIMIT 5". That little call to RAND() makes generating this from JPA a huge pain.

3) Manual session life cycle management is terrible. It shouldn't be needed. This leads to all sorts of terrible hacks to get around it, ConversationScopes(CDI in general), opening transactions in the JSF RENDER_RESPONSE phase just so lazy loading works, etc, etc. Having used JavaEE stuff for awhile now I'm convinced a large portion of the cruft exists to support this model of session management. All the additional scopes and requisite CDI support seem to have all been created as workaround to just deal with session lifecycle.

Re: Build RESTful web services with Java technology

#20
post #16

Earlier quoted context omitted.

You don't need JSON configuration even if it was existing. You can use annotation based configuration (meaning Java classes with annotations like @Configuration, @EnableWebMvc etc..) for > 90% of the configuration cases: http://blog.springsource.org/2011/06/10/spring-3-1-m2-config...

I prefer plain files instead of annotations. Just wish the non-readability of XML would go away with less bloated format (which other frameworks did with JSON).

Fair enough argument :)

Though, now that I've gotten into the annotation way I like it the most.

Post reply on HN