title: How access a @Lob field from an EJB3 extended persistence context
body: <p>We're developing a project in <strong>JaveEE6</strong>, using <strong>EJB3</strong> beans and <strong>JPA2</strong> annotations.</p>
  
  <p>We have some stateful EJB3 beans that use <strong>extended persistence context</strong> in order to display the database entities to the front (through some interfaces, removing the need of DTO).</p>
  
  <p>The typical use is something like:</p>
  
  <ul>
  <li>all methods are without transaction, as we don't want to immediately commit user modification </li>
  <li>through a non-transactional method, we're loading the entity, attached to the extended context</li>
  <li>only a save method is transactional: after checking the user data, the entity is then committed and persisted in database.</li>
  </ul>
  
  <hr>
  
  <p>With a MySQL database, everything works just fine.</p>
  
  <p>Alas, on <em>Postgres</em>, a problem occurs with <code>@Lob</code> field loaded in non-transactional methods. JDBC seems to forbid Lob access outside transaction, throwing a:
  <strong><code>org.hibernate.exception.GenericJDBCException: Large Objects may not be used in auto-commit mode</code></strong></p>
  
  <hr>
  
  <p>As a <a href="https://stackoverflow.com/a/3164352/923712">stackoverflower pointed</a>, a Lob can be in multiple records, so it needs a transaction to maintain consistency.</p>
  
  <p>Set <code>autocommit</code> to true in <code>persistence.xml</code> doesn't work at all, and also <a href="https://stackoverflow.com/a/1667859/923712">should not be done</a>.</p>
  
  <p>I cannot make the method transactional, as we don't want to commit anything at the end of the call. So, does anyone know how can I simply access the Lob?</p>
  
  <p>A hack solution we imagine would be to move the Lob in another entity, then add a transactional method that read the Lob content so we can use it. Quite dirty I think...</p>