This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dependency Injection: Field injection and Setter Injection.

 
Rahul Ba
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to the EJB3. Can anybody tell me what is the difference between field Injection and Setter Injection. I got the Field Injectionn but not the Setter Injection. What is the use of the settert Injection and why we need that?
 
Faraz Ali
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

There is field-based persistence and property-based persistence. In feild-based persistence, annotations are applied directly on instance variable, while in property-based persistence, annotations are applied on getter methods.

I think its all upon your personal taste. Field-based persistence is easier to use but property-based persistence allows data hiding. So its upto you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic