I wrote my first session
EJB's from scratch yesterday and deployed them on glassfish. However, they act exactly opposite of what I thought would happen. Here is the scenario:
I have 2 beans StatefulCounter and StatelessCounter, they have the exact same code except for the name. Here are the relevant bits:
private int count = 0;
public void increment() {
count += 1;
}
public
String getCount() {
return String.valueOf(count);
}
Verry simple.
I then have a
JSP that increments then displays the count of each bean. Here are the relevant bits:
<% InitialContext ic = new InitialContext();
Object oRef = ic.lookup( "StatelessCounter" );
StatelessCounterHome statelessHome = (StatelessCounterHome)PortableRemoteObject.narrow( oRef, StatelessCounterHome.class);
less = statelessHome.create();
Object oRef2 = ic.lookup("StatefulCounter");
StatefulCounterHome statefulHome = (StatefulCounterHome)PortableRemoteObject.narrow(oRef2, StatefulCounterHome.class);
ful = statefulHome.create();
less.increment();
ful.increment();
%>
<table border=1>
<tr>
<td>
Stateless counter: <%=less.getCount()%>
</td>
<td>
Stateful counter: <%=ful.getCount()%>
</td>
</tr></table>
However, when I keep hitting the reload button on FF, the stateless counter goes up, and the stateful counter stays at 1. This is exactly the opposite of what I thought would happen.
Also, here is the relevant ejb-jar.xml:
<session>
<ejb-name>StatelessCounterEJB</ejb-name>
<mapped-name>StatelessCounter</mapped-name>
<description>Simple session bean example</description>
<home>com.pos.ejb.test.home.StatelessCounterHome</home>
<remote>com.pos.ejb.test.remote.StatelessCounterRemote</remote>
<ejb-class>com.pos.ejb.test.StatelessCounter</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
</session>
<session>
<ejb-name>StatefulCounterEJB</ejb-name>
<mapped-name>StatefulCounter</mapped-name>
<description>Simple session bean example</description>
<home>com.pos.ejb.test.home.StatefulCounterHome</home>
<remote>com.pos.ejb.test.remote.StatefulCounterRemote</remote>
<ejb-class>com.pos.ejb.test.StatefulCounter</ejb-class>
<session-type>Stateful</session-type>
<transaction-type>Bean</transaction-type>
</session>
What concept am I missing?