viernes, 27 de julio de 2007

Problemas con Hibernate y @Where

Intenté utilizar @Where en un proyecto, donde una clase esta mapeada asi:

@Where(clause="borrada = false")
private List opciones;

La lista posee instancias de 'Opcion' y quiero que NO se incluyan las borradas (Opcion posee un campo booleano llamado 'borrada').

Eso NO funciona y genera una Excepcion:

org.postgresql.util.PSQLException: ERROR: column opciones0_.false does not exist


org.hibernate.exception.SQLGrammarException: could not initialize a collection: [xxxxxxxxxxxxxxxx.PreguntaMultipleOpcion.opciones#201]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1992)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
at org.hibernate.collection.PersistentBag.iterator(PersistentBag.java:249)
.............
Caused by: org.postgresql.util.PSQLException: ERROR: column opciones0_.false does not exist
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1512)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1297)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:188)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:430)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:346)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:250)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1778)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1985)
... 29 more
... Removed 21 stack frames




El problema es que genera un SQL erroneo:

from Opcion opciones0_ where ( opciones0_.borrada = opciones0_.false)

Utilizando PostgreSql 8, encontré una forma de hacerlo funcionar:

@Where(clause="borrada = ('false'::BOOLEAN)")

esto genera un SQL correcto:

from Opcion opciones0_ where ( opciones0_.borrada = ('false'::BOOLEAN))

Será esto un bug, o es el funcionamiento normal de Hibernate?

No hay comentarios: