I recently started backend programming with Java servlets to access data for intranet webapps.
I’ve created a servlet that passes a query name to a stored procedure on the database and then returns the result as a chunk of JSON. I use this from AJAX calls in the webapps. My webapps only have a maximum of about 100 users on them – this number will grow slowly over the next year though.
I would like to use hibernate for connection pooling as opposed to opening and closing a JDBC connection for every AJAX call. But each of the hibernate tutorials I have been through start out with creating POJOs to map the data, with getters and setters. I would’t really use the POJO methods at all – currently I create the JSON from the resultset object with a stringbuilder and don’t really see why I would need to change that.
Basically, I would like to simply change my servlet to call some kind of hibernate connection pool object instead of creating a JDBC connection.
Can I / should I be using hibernate for this purpose (just connection pooling without POJOs)? If so does anyone know a tutorial that just focuses on this? If not should I be using something else for this?
As I said, I am pretty new to server side programming so I may just missing some fundamental concept. Any direction is appreciated.
Hibernate is a tool for Object-relational mapping, and as such is good for mapping Java objects to tables. If you want to use JDBC to execute queries and continue using your builder to convert sql resultsets to JSON, you don’t need or want Hibernate, and you don’t need it for connection pools.
You should be looking at tools like Dbcp or 3cp0 that are focused on providing connection pooling capability rather than Hibernate.