-
1. Re: Getting reference to Local Interface
sseaman Sep 25, 2002 10:51 AM (in response to sseaman)Figured it out on my own.
For those who might want the answer:
You need to define an <ejb-local-ref> tag set within your ejb-jar.xml
Say you have an entity bean named User and you want to be able to get to it locally. In the tags for the User bean you need to have the following:
<ejb-local-ref>
<!-- this is what to use in the lookup -->
<ejb-ref-name>local/User</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<local-home>com.blah.entity.UserHome</local-home>
com.blah.entity.User
<!-- this is the entity bean -->
<ejb-link>User</ejb-link>
</ejb-local-ref>
Please note that com.blah.entity.UserHome and com.blah.entity.User implement the Local interfaces. Most people would have them named UserLocalHome and UserLocal, but I used JBuilder to make the beans (took too long in JEdit) and JBuilder names them differently.
Anyway, in your code, to reference the local interfaces you would do the following:
// Get the reference to the LOCAL Home
UserHome home = (UserHome)ctx.lookup("local/User");
// Get the reference to the LOCAL User object
User user = (User)home.findByEmailAddress("sloan@sgi.net");
// Print some stuff
System.out.println(user.getEmailAddress()+
" "+user.getPassword());
// This actually returns another LOCAL object
// that is created by an ejb-relationship.
System.out.println(user.getLeagueContact().
getFirstName());
And that is really all that there is to it.
Remember that when dealing with ejb-relationships, they only work locally. So the code above would have to be in a bean within the same JVM as the User objects.