4

what we are planning to do is we want a single project but want to use three different frame works to-gather, so is it a good idea or can this is achievable ?

we have already project build up with spring and hibernate but we want to extend it with jdbc template.

please guide on common quetions like -New Session factory required or not ? -Can we use pojos with hibernate annotations with jdbc template or we have to create new one ? -Will this create problem on performance if average is 500 users at a time ?

Thanks in advance.

Mitul
  • 131
  • 2
  • 9

1 Answers1

3

Using both an ORM and JDBC in the same application is a reasonable thing to do. Hibernate can run native SQL queries so you might consider that as an alternative depending on what you have in mind.

JDBC doesn't use a session factory or entity manager factory comparable to Hibernate. Caching for the JDBC results would have to be handled separately from Hibernate.

The Hibernate/JPA annotations will be irrelevant to JDBC queries, the RowMapper passed into the query controls how pojos get populated. You could re-use your Hibernate entities to be populated by the rowmappers but in practice the reason you use JDBC is to get more focused results with flatter objects and you end up with a separate set of DTOs.

I'm not clear on what you think is going to hurt performance here. JDBC should be an improvement over Hibernate performance-wise, though at the cost of having business-logic spread out in multiple places. The tricky part will probably be setting up the transaction manager so that JDBC and Hibernate use the same transaction, see this question.

Community
  • 1
  • 1
Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276
  • Hey Nathan, It is really understandable but I got a query regarding what for mapping used in hibernate's POJO? If I fetch one object from hibernate and other one with jdbc template can I set that object in each other and can use it? Here hibernate object is persistent and jdbctemplate is not so will it make changes to data if I set jdbctemplate object into hibernate object while doing some CRUD operations? – commit May 15 '14 at 15:00
  • @commit: yes, you could possibly change data inadvertently doing that kind of thing. one way around would be another layer of dtos, or copying the other way around from the hibernate entity to the jdbc-created one. Setting up a readonly transaction would probably help too. – Nathan Hughes May 15 '14 at 15:04