[
https://hibernate.onjira.com/browse/HHH-5858?page=com.atlassian.jira.plug...
]
Ralf Huthmann commented on HHH-5858:
------------------------------------
Sorry it took me so long to come back to this issue. The code shown below is in use for
reading CLOBs with a stateless session and i have not encountered any issues. Please
perform additional tests for your usecase. To use my replacement-class, i construct a
stateless session this way:
{code}
Connection con = session.connection();
SessionFactory sf = session.getSessionFactory();
StatelessSessionWithLobImpl sls = new StatelessSessionWithLobImpl(con,
(SessionFactoryImpl) sf);
{code}
Finally, this is the replacement for StatelessSessionImpl:
{code}
package org.hibernate.impl;
import org.apache.log4j.Logger;
import org.hibernate.Session;
import org.hibernate.StatelessSession;
import org.hibernate.engine.jdbc.LobCreationContext;
import org.hibernate.exception.JDBCExceptionHelper;
import java.sql.Connection;
import java.sql.SQLException;
/**
* Replacement for StatelessSessionImpl implementing LobCreationContext,
* this enables the use of LOBs with a stateless session.
* The execute-method in this class was copied from SessionImpl.
* @see
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5858
*/
public class StatelessSessionWithLobImpl
extends StatelessSessionImpl
implements LobCreationContext
{
private static final long serialVersionUID = 6444431664782394430L;
private static final Logger LOGGER =
Logger.getLogger(StatelessSessionWithLobImpl.class);
public StatelessSessionWithLobImpl(Connection connection,
SessionFactoryImpl factory) {
super(connection, factory);
}
@Override
public Object execute(Callback callback) {
Object result;
Connection connection = super.connection();
boolean success = false;
try {
result = callback.executeOnConnection( connection );
success = true;
}
catch ( SQLException e ) {
throw JDBCExceptionHelper.convert(
getFactory().getSQLExceptionConverter(),
e,
"Error creating contextual LOB : " + e.getMessage()
);
}
finally {
afterOperation(success);
}
try {
connection.close();
}
catch (SQLException e) {
LOGGER.error("Kann man nichts machen", e);
}
return result;
}
}
{code}
Cannot load entities with Clob or Lob properties into stateless
sessions
------------------------------------------------------------------------
Key: HHH-5858
URL:
https://hibernate.onjira.com/browse/HHH-5858
Project: Hibernate ORM
Issue Type: Bug
Components: core
Affects Versions: 3.5.1
Reporter: James Roper
I have a an entity with a Clob property:
{code:java}
@Lob
private Clob clobProperty;
{code}
When I try and load it in a stateless session, I get:
{noformat}
Exception in thread "main" java.lang.ClassCastException:
org.hibernate.impl.StatelessSessionImpl cannot be cast to
org.hibernate.engine.jdbc.LobCreationContext
at org.hibernate.Hibernate.getLobCreator(Hibernate.java:420)
at org.hibernate.type.ClobType.nullSafeGet(ClobType.java:114)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:105)
at
org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2267)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1423)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1351)
at org.hibernate.loader.Loader.getRow(Loader.java:1251)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:619)
at org.hibernate.loader.Loader.loadSingleRow(Loader.java:307)
at
org.hibernate.impl.ScrollableResultsImpl.prepareCurrentRow(ScrollableResultsImpl.java:254)
at org.hibernate.impl.ScrollableResultsImpl.next(ScrollableResultsImpl.java:123)
{noformat}
If Lobs in stateless sessions isn't supported, then at very least an error message to
that effect should be thrown and the docs should be updated to reflect this, but I
don't see why that should be the case, especially considering that both Lobs and
stateless session both serve very similar purposes, they are for use when dealing with
large datasets that may not fit in memory, and so could well be used together.
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira