В настоящее время я изучаю новые модели компонентов Java EE 6 и меня смущает последний механизм внедрения зависимостей. Итак, вот мои вопросы:
1) В чем разница между @Inject и @EJB
2) Если у меня есть простой POJO, который содержит другие POJO (какой из них является кодом DAO), что будет лучший выбор: @Inject или @EJB?
Могу ли я смешать @Inject и @EJB?
Пример: an instance of ClassA_Adaptor
ClassA_Adaptor implements InterfaceAB and has an instance of ClassB
ClassB implements InterfaceB and has an instance of ClassB_Adaptor and an instance DAO_ClassB
ClassB_Adaptor implements InterfaceB and has an instance of ClassC
ClassC implements InterfaceBC and has an instance of WebService_ClassC
DAO_ClassB will use JPA 2.0 (@PersistenceContext)
I'd like to inject all of them including the DAO and the WebService.
3) Is it a bad approach to only use transactional for certain operations but not for all?
As an example: Some methods in DAO_ClassB are your typical query, while other methods are "write" methods. Is it bad to not wrap the "READ" methods with transaction?
To my understanding, the DAO_ClassB can be wrapped with transaction using @EJB (inject the DAO_ClassB and make all methods transactional). How can I control it?
Sorry if some of the questions are confusing because I know only bits and pieces of the Java EE 6 new component model.