Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using JPA and JDBC together

 
anis frikha
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
first, I'm a new member and I hope that my post is in the right section

I want use EJB3 in my application but the problem is that I canno't map a table wich contains financial market data (over 100 000 rows per table), I need to extract them from the database to do some treatements and inject the result into entity bean.
I thing that the solution is to use, in parallel to JPA, a stateless session bean as a JDBC DAO, but I don't know if this will not causes problem like concurrent access with the entity manager at the DB level and how manage transactions when using this DAO i.e how the container will manage the rollback of the JDBC DAO ?

Thanks for your help and sorry for my english
 
Tim Holloway
Saloon Keeper
Posts: 18367
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Anis!

Don't worry about your English, you're not doing any worse than some who grew up speaking it. Computer people tend to be bad with language - unless it's computer language!

Most of the time There's no benefit to using JDBC if you have JPA. In fact, ORM tends to be more efficient than raw JDBC when you're dealing with large complex situations. Plus, as you've guessed, you have to do your own transaction management when you use JDBC directly.

A stateless session bean can serve as a DAO responsible for access of JPA objects and as part of that functionality, it must be designed to handle transactions and rollbacks in whatever way works best for the problems it's designed to handle.

In your case, when I say "JPA objects" I mean EJB3 Entity EJBs, but JPA also works quite well with non-EJB persistable objects. I do it all the time.
 
anis frikha
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your reply Tim

I think that my problem is typically a situation when ORM canno't work efficiently because, I didn't test, but loading 100 000 Entity beans, will hardly decrease performance !

it's impossible to return ResultSet, primitive objects (integer, double,...) or another thing that isn't EJB3 Entity, with the entity manager or the persistence unit ? (it seems to be impossible with Nativ Query)
 
anis frikha
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems to be possible to encapsulate a JDBC call into a JTA transaction if the driver has an implementation of XADataSource, but I don't now if it's a standard practice, any information about that ?
 
Per Lindberg
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this problem, too. I handle a business database very nicely with JPA. But I also have another database with historical data with gazillions of records, where I feel that I must use JDBC calls directly. Both databases run on InnoDB/MySQL. I do the business logic in EJB3 stateless beans. A typical EJB method call does both JPA and JDBC operations.

Now, is there a way to "connect" the JDBC transaction and the EJB3/JPA transaction? How?

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic