Originally posted by nitin pai:
I am not clear as to why the annotation in the first line is used:
@Resource(name="jdbc/EmployeeAppDB", type=javax.sql.DataSource)
because anyways the code uses JNDI to get the context. So is the resource injection actually required?
Nitin,
The "name" attribute for the @Resource annotation is
not used for looking up the resource for injection. Instead, the resource will be bound to the
java:comp/env/<the value you specify for the "name"> (in this example, it will be bound to java:comp/env/jdbc/EmployeeAppDB after injection). As you can see, later on in the changePhoneNumber code, the resource is looked up at java:comp/env/jdbc/EmployeeAppDB. If you hadn't used the "name" attribute then this wouldn't have been possible.
[ June 11, 2008: Message edited by: Jaikiran Pai ]