Reputation: 19
I only want to use EJB3 and DAO objects for the DAO layer. I'd like to avoid JPA as it is possible.
The use case is as follows:
DAOObject.putOrder()
DAOObject
uses Spring jdbcTemplate
to query the database.Is this possible? How is the transaction scope affected.
Please an example would be great.
Upvotes: 1
Views: 708
Reputation: 691635
Of course it's possible. Inject a DataSource in your DAO (using the @Resource
) annotation, construct a JdbcTemplate from this injected DataSource, and use the JdbcTemplate inside the DAO methods. The DataSource will return a Connection which is tied to the current JTA transaction.
Upvotes: 1
Reputation: 340708
You are free to use EJB without JPA. Just don't use it :-).
Transactions are managed on a connection level by the DataSource
so you are free to use both JDBC and JPA, even in one project. Of course raw JDBC should work as well. Remember that by default every EJB session bean method is transactional.
Upvotes: 2