user1872598
user1872598

Reputation: 19

EJB3 without JPA

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:

  1. My EJB3 invokes the DAOObject.putOrder()
  2. The 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

Answers (2)

JB Nizet
JB Nizet

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

Tomasz Nurkiewicz
Tomasz Nurkiewicz

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

Related Questions