Tentei isso também:
@Column(updatable = false, insertable = false)
@Formula("( select s.* from Serv as s where s.chvserv=chvproserv ) ")
public Serv getServico() {
return servico;
}
Mas acabei de descobrir que @formula aceita somente SQL e não HSQL
Erro:
[code]Hibernate: select this_.chvos as chvos1_, this_.chvbfj as chvbfj3_1_,
this_.dem as dem3_1_, this_.det as det3_1_, this_.dtval as dtval3_1_,
this_.dua as dua3_1_, this_.nf as nf3_1_, this_.nped as nped3_1_,
this_.npedC as npedC3_1_, this_.orc as orc3_1_, this_.res as res3_1_,
this_.usr as usr3_1_, this_.vldesc as vldesc3_1_, this_.vlimp as vlimp3_1_,
this_.vlpro as vlpro3_1_, this_.vlser as vlser3_1_, this_.vltot as vltot3_1_,
this_.chvvnd as chvvnd3_1_, this_.status as status3_1_, osi2_.chvos as
chvos3_, osi2_.chvosi as chvosi3_, osi2_.chvosi as chvosi0_, osi2_.dua as
dua4_0_, osi2_.usr as usr4_0_, osi2_.chvesq as chvesq4_0_,
osi2_.chvproserv as chvproserv4_0_, osi2_.cmi as cmi4_0_, osi2_.icm as
icm4_0_, osi2_.ipi as ipi4_0_, osi2_.iss as iss4_0_, osi2_.chvos as
chvos4_0_, osi2_.qtd as qtd4_0_, osi2_.serv as serv4_0_, osi2_.vlu as
vlu4_0_, osi2_.vtot as vtot4_0_, ( select s.* from Serv as s where
s.chvserv=osi2_.chvproserv ) as formula0_0_ from Os this_ left outer join
Osi osi2_ on this_.chvos=osi2_.chvos
Exception in thread “main” org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:82)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1596)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:111)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1322)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:300)
at br.com.centauro.dao.Dao.listAtPage(Dao.java:47)
at br.com.empresario.modelo.dao.TesteClasses.testeOs(TesteClasses.java:70)
at br.com.empresario.modelo.dao.TesteClasses.main(TesteClasses.java:116)
Caused by: java.sql.SQLException: [Microsoft][Driver ODBC para Microsoft
Access] Você gravou uma subconsulta que pode retornar mais de um
campo sem usar a palavra reservada EXISTS na cláusula FROM da
consulta principal. Reveja a instrução SQL da subconsulta para que a
mesma solicite apenas um campo.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
at sun.jdbc.odbc.JdbcOdbc.SQLExecute(JdbcOdbc.java:3150)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(JdbcOdbcPreparedStatement.java:214)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeQuery(JdbcOdbcPreparedStatement.java:89)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:75)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:120)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1272)
at org.hibernate.loader.Loader.doQuery(Loader.java:391)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
… 7 more[/code]