For simple POJOs that are not EJBs, are they allowed to do direct file I/O ?

Solution Verified - Updated -

Environment

Red Hat JBoss Enterprise Application Platform (EAP) 5.2.0

Issue

According to the EJB specifications, it forbidden to do direct file I/O (like opening an InputStream and accessing the file system directly) from an EJB.
What about simple POJOs that are not EJBs? Is it allowed to do direct file I/O from that classes? And what if a POJO is called from an EJB. Do the EJB-restrictions then aplly to that POJO too?

Resolution

That restriction applies to the POJO as well.

Any access to I/O regardless of whether it is the EJB itself or a used POJO/Utility class will be a violation of the EJB spec.

The reasoning behind this is that only the server is responsible for providing access to the environment

  • Threads
  • Resources like sockets, files, configuration, connections - AKA I/O

If the drawback of OS dependency, and possible migration problems are accepted, it can be used.
In the event that this approach is being considered, then you may need to rethink the architecture.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments