I am studying/experimenting with EJBs. I have an EJB with an overridden toString method:
@Stateless
@LocalBean
public class FlightService {
...
@Override
public String toString() {
return "FlightService [id=" + id + ", from=" + from + ", to=" + to + ", price=" + price + ", airplaneModel="
+ airplaneModel + "]";
}
}
In my servlet, I inject this EJB into a variable, like this:
@EJB
private FlightService fs;
However, when I would like to print it out..
if (fs != null){
out.println("Flight details: " + fs.toString());
}
.. I get the following output, which is what I would get with the defaul toString method, I think.
Flight details: com.airline.service.__EJB31_Generated__FlightService__Intf___754270295
Instead of
Flight details: FlightService [id=123, ...]
as I would expect. All other functionalities of the EJB are working as expected, as far as I can tell. Can someone please explain to me what happens with the toString method? Thank you!
EDIT: It works with explicitly created objects (new FlightService()), as suggested by Soumitri Pattnaik.
EDIT2: Full source available on pastebin. FlightService.java, FlightDetails.java The project was created in Eclipse, running on Glassfish 4.