-2

I would like to know the difference between creating an DAO Object with constructor like :

myDaoObject = new MyDaoObject();

and creating it by EJB injection :

@EJB
MyDaoObject myDaoObject;

Is there a difference in the running and/or performance ? thanks.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
ThunderPhoenix
  • 1,649
  • 4
  • 20
  • 47
  • possibly duplicate http://stackoverflow.com/questions/7662501/is-it-deemed-bad-practice-to-inject-the-dao-into-the-constructor-and-if-so-why – Muhammad Aug 28 '13 at 09:18
  • You seem to have completely missed the point of EJBs. This is not just like decoration. I suggest to carefully read this answer: http://stackoverflow.com/a/18379228 – BalusC Aug 28 '13 at 12:36

1 Answers1

4

Well...you really can't create EJBs with constructor because you would lose the functionality offered by the container (dependency injection, pooling, calling of @PostConstruct, transactions, ...). So only correct way is

@EJB
MyDaoObject myDaoObject;

P.S. Or, in case you are using CDI, @Inject instead of @EJB

Petr Mensik
  • 26,874
  • 17
  • 90
  • 115