1
I have a method:
public static List<Texto> getTextoPorIdAlternativoLike(String idAlternativoTexto) {
Texto texto = new Texto();
String where = "t.idAlternativo like :idAlternativo";
List<NameValuePair> whereParameters = new ArrayList<NameValuePair>();
whereParameters.add(new NameValuePair("idAlternativo",
idAlternativoTexto));
List<Texto> result = texto.read(where, whereParameters);
if (result == null) {
result = new ArrayList<Texto>();
}
return result;
}
When I call the method, I call it this way:
List<Texto> listaTextos = getTextoPorIdAlternativoLike("1*casa-aberta" + "%");
And the read() method is as follows:
public List<T> read(String where, List<NameValuePair> whereParameters){
initializeEntityManager();
List<T> list = new ArrayList<T>();
boolean closeTransaction = false;
try {
if (!entityManager.getTransaction().isActive()) {
logger.debug("\n*** Starting transaction \n");
entityManager.getTransaction().begin();
closeTransaction = true;
}
String hQl = "from " + this.getClass().getSimpleName() + " t ";
// String hQl = "from T t ";
System.out.println(hQl);
if ((where != null) && (!where.trim().isEmpty())) {
hQl += " where " + where;
System.out.println(hQl);
}
Query query = entityManager.createQuery(hQl);
if ((where != null) && (!where.trim().isEmpty())) {
if (whereParameters != null) {
for (NameValuePair par : whereParameters) {
logger.debug("Set attribute: " + par.getName());
query.setParameter(par.getName(), par.getValue());
}
}
}
list = query.getResultList();
if (entityManager.getTransaction().isActive()) {
if (closeTransaction) {
logger.debug("\n*** Commiting transaction \n");
entityManager.getTransaction().commit();
}
}
} catch (Exception e) {
if (entityManager.getTransaction().isActive()) {
if (closeTransaction) {
logger.debug("\n*** Rollback transaction\n");
entityManager.getTransaction().rollback();
}
}
throw e;
} finally {
if (closeTransaction) {
logger.debug("\n*** Closing EM\n");
entityManager.close();
}
}
return list;
}
The generated query is:
from Text t Where (t.documentSource = :documentSource) and (t.idAlternative like :idAlternative) and (dataDesativacao is null) 2016-05-13 15:35:34 DEBUG Abeandao:604 - HQL: 2016-05-13 15:35:35 DEBUG Abeandao:605 - from Texto t Where (t.documentSource = :documentSource) and (t.idAlternative like :idAlternative) and (dataDesativacao is null) 2016-05-13 15:35:37 DEBUG QueryTranslatorImpl:294 - parse() - HQL: from br.com.lexplena.model.documento.Texto t where (t.documentoFonte = :documentoFonte) and (t.idAlternativo like :idAlternativo) and (dataDesativacao is null) 2016-05-13 15:35:37 DEBUG Querytranslatorimpl:312 - --- HQL AST --- -[QUERY] Node: 'query' +-[SELECT_FROM] Node: 'SELECT_FROM' | -[FROM] Node: 'from' | -[RANGE] Node: 'RANGE' | +-[DOT] Node: '.' | | +-[DOT] Node: '.' | | | +-[DOT] Node: '.' | | | | +-[DOT] Node: '.' | | | | | | +-[DOT] Node: '.' | | | | | | +-[IDENT] Node: 'br' | | | | | | -[IDENT] Node: 'com' | | | | | -[IDENT] Node: 'lexplena' | | | | -[IDENT] Node: 'model' | | | -[IDENT] Node: 'document' | | -[IDENT] Node: 'Text' | -[ALIAS] Node: ’t' -[WHERE] Node: 'Where' -[AND] Node: 'and' +-[AND] Node: 'and' | +-[EQ] Node: '=' | | +-[DOT] Node: '.' | | | | +-[IDENT] Node: ’t' | | | -[IDENT] Node: 'documentFonte' | | -[COLON] Node: ':' | | -[IDENT] Node: 'documentFonte' | -[LIKE] Node: 'like' | +-[DOT] Node: '.' | | +-[IDENT] Node: ’t' | | -[IDENT] Node: 'idAlternative' | -[COLON] Node: ':' | -[IDENT] Node: 'idAlternative' -[IS_NULL] Node: 'is null' -[IDENT] Node: 'dataDesativacao'
2016-05-13 15:35:37 DEBUG Errorcounter:113 - throwQueryException() : no errors 2016-05-13 15:35:37 DEBUG Hqlsqlbasewalker:121 - select << Begin [level=1, statement=select] 2016-05-13 15:35:37 DEBUG Fromelement:158 - Fromclause{level=1} : br.com.lexplena.model.documento.Text (t) -> texto0_ 2016-05-13 15:35:37 DEBUG Fromreferencenode:77 - Resolved : t -> texto0_.idText 2016-05-13 15:35:37 DEBUG DotNode:666 - getDataType() : documentoFonte -> org.hibernate.type.ManyToOneType(br.com.lexplena.model.documento.DocumentoFonte) 2016-05-13 15:35:37 DEBUG Dotnode:625 - dereferenceShortcut() : Property documentFonte in br.com.lexplena.model.documento.Text does not require a Join. 2016-05-13 15:35:37 DEBUG Dotnode:653 - Terminal getPropertyPath = [documentSource] 2016-05-13 15:35:37 DEBUG Fromreferencenode:77 - Resolved : t.documentSource -> texto0_.idDocument 2016-05-13 15:35:37 DEBUG Fromreferencenode:77 - Resolved : t -> texto0_.idText 2016-05-13 15:35:37 DEBUG Dotnode:666 - getDataType() : idAlternative -> org.hibernate.type.Stringtype@44824d2a 2016-05-13 15:35:37 DEBUG Fromreferencenode:77 - Resolved : t.idAlternative -> texto0_.idAlternative 2016-05-13 15:35:37 DEBUG Fromreferencenode:77 - Resolved : {Synthetic-alias} -> {Synthetic-alias} 2016-05-13 15:35:37 DEBUG Dotnode:666 - getDataType() : dataDesativacao -> org.hibernate.type.Calendartype@5efd28f7 2016-05-13 15:35:37 DEBUG Fromreferencenode:77 - Resolved : {Synthetic-alias}. dataDesativacao -> texto0_.dataDesativacao 2016-05-13 15:35:37 DEBUG Hqlsqlbasewalker:125 - select : Finishing up [level=1, statement=select] 2016-05-13 15:35:37 DEBUG HqlSqlWalker:671 - processQuery() : ( SELECT ( FromClause{level=1} Texto texto0_ ) ( where ( and ( and ( = ( texto0_.idDocumentoFonte texto0_.idTexto documentoFonte ) ? ) ( like ( texto0_.idAlternativo texto0_.idTexto idAlternativo ) ? ) ) ( is null ( texto0_.dataDesativacao {Synthetic-alias} dataDesativacao ) ) ) ) 2016-05-13 15:35:37 DEBUG Hqlsqlwalker:947 - Derived SELECT clause created. 2016-05-13 15:35:37 DEBUG Joinprocessor:187 - Using FROM Fragment [Text texto0_] 2016-05-13 15:35:37 DEBUG Hqlsqlbasewalker:129 - select >> end [level=1, statement=select] 2016-05-13 15:35:37 DEBUG Querytranslatorimpl:281 - --- SQL AST --- -[SELECT] Querynode: 'SELECT' querySpaces (Text) +-[SELECT_CLAUSE] Selectclause: '{derived select clause}' | +-[SELECT_EXPR] Selectexpressionimpl: 'texto0_.idText as idTexto1_31_' {Fromelement{Explicit,not a Collection Join,not a fetch Join,fetch non-lazy properties,classAlias=t,role=null,tableName=Text,tableAlias=texto0_,origin=null,Columns={,classname=br.com.lexplena.model.document.Text}}}} | -[SQL_TOKEN] Sqlfragment: 'texto0_.binario as binario2_31_, texto0_.idCrawlerConfig as idCrawl21_31_, texto0_.dateCreation as dataCria3_31_, texto0_.dateDevacao as dataDesa4_31_, texto0_.idDocumentSource as idDocum22_31_, texto0_.idAltern5_31_, texto0_.nodeNameAnterior as nodeName6_31_, texto0_.nodeNamePosterior as nodeName7_31_, texto0_.idNorma as idNorma23_31_, texto0_.ordemExi8_31_, texto0_.idParteDoText as idParte24_31_, texto0_.parteDextoTextoInstancia as parteDoT9_31_, texto0_.posicao as posicao10_31_, texto0_.pronto as read11_31_, texto0_.regra as regra12_31_, texto0_.idSuperEstruturaTextual as idSuper25_31_, texto0_.idTextoAnterior as idTexto26_31_, texto0_.textoBruto as textoBr13_31_, texto0_.textoEd14_31_, texto0_.text texto0_.textoFonetico as textoFo16_31_, texto0_.textoPesquisavel as textoPe17_31_, texto0_.versionAlteracao as versaoA18_31_, texto0_.vigenciaInicio as vigenci19_31_, texto0_.vigenciaTermino as vigenci20_31_' +-[FROM] FromClause: 'from' FromClause{level=1, fromElementCounter=1, fromElements=1, fromElementByClassAlias=[t], fromElementByTableAlias=[texto0_], fromElementsByPath=[], collectionJoinFromElementsByPath=[], impliedElements=[]} | -[FROM_FRAGMENT] FromElement: 'Texto texto0_' FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=t,role=null,tableName=Texto,tableAlias=texto0_,origin=null,columns={,className=br.com.lexplena.model.documento.Texto}} -[WHERE] Sqlnode: 'Where' -[AND] Sqlnode: 'and' +-[AND] Sqlnode: 'and' | +-[EQ] Binarylogicoperatornode: '=' | | +-[DOT] Dotnode: 'texto0_.idDocumentSource' {propertyName=documentSource,dereferenceType=UNKNOWN,getPropertyPath=documentSource,path=t. documentSource,tableAlias=texto0_,classname=br.com.lexplena.model.document.Text,classAlias=t} | | | +-[ALIAS_REF] IdentNode: 'texto0_.idTexto' {alias=t, className=br.com.lexplena.model.documento.Texto, tableAlias=texto0_} | | | -[IDENT] Identnode: 'documentFonte' {originalText=documentFonte} | | -[NAMED_PARAM] ParameterNode: '?' {name=documentoFonte, expectedType=org.hibernate.type.ManyToOneType(br.com.lexplena.model.documento.DocumentoFonte)} | -[LIKE] Binarylogicoperatornode:}
2016-05-13 15:35:37 DEBUG Errorcounter:113 - throwQueryException() : no errors 2016-05-13 15:35:37 DEBUG QueryTranslatorImpl:263 - HQL: from br.com.lexplena.model.documento.Texto t where (t.documentoFonte = :documentoFonte) and (t.idAlternativo like :idAlternativo) and (dataDesativacao is null) 2016-05-13 15:35:37 DEBUG Querytranslatorimpl:264 - SQL: select texto0_.idText as idTexto1_31_, texto0_.binario as binario2_31_, texto0_.idCrawlerConfig as idCrawl21_31_, texto0_.dataCreation as dataCria3_31_, texto0_.dataDesativacao asdataDesa4_31_, texto0_.idDocumentSource as idDocum22_31_, texto0_.idAltern5_31_, texto0_.nodeNameAnterior as nodeName6_31_, texto0_.nodeNamePosterior as nodeName7_31_, texto0_.idNorma as idNorma23_31_, texto0_.ordemExi8_31_, texto0_.idParteDexto as idParte24_31_, texto0_.parteDextoTextoInstance aspartDoT9_31_, texto0_.position as posicao10_31_, texto0_.pronto as read11_31_, texto0_.rule as regra12_31_, texto0_.idSuperStructuraText as idSuper25_31_, texto0_.idTextoTexto26_31_, texto0_.textoBruto astextoBr13_31_, texto0_.textEd14_31_, texto0_.textEx15_31_, textoFonetico as textoFo16_31_, texto0_.textoPesquisavel as textoPe17_31_, texto0_.versionAlteracao as versaoA18_31_, texto0_.vigenciaInicio as vigenci19_31_, text0_.vigenciaTermino as vigenci20_31_ from Text text0_Wheretext0_.idDocument=? and (texto0_.idAlternative like ?) and (texto0_.dataDesativacao is null) 2016-05-13 15:35:37 DEBUG Errorcounter:113 - throwQueryException() : no errors
It turns out it ends in an infinite loop on list = query.getResultList();
, bursting the error as he makes several queries to the bank:
Java.lang.Stackoverflowerror:
Part of Log error
java.lang.Stackoverflowerror at java.nio.Charbuffer.arrayOffset(Charbuffer.java:986) at sun.nio.Cs.UTF_8.updatePositions(UTF_8.java:77) at sun.nio.Cs.UTF_8$Encoder.overflow(UTF_8.java:500) at sun.nio.Cs.UTF_8$Encoder.encodeArrayLoop(UTF_8.java:530) at sun.nio.Cs.UTF_8$Encoder.encodeLoop(UTF_8.java:619) at java.nio.charset.CharsetEncoder.Ncode(Charsetencoder.java:561) at sun.nio.Cs.StreamEncoder.implWrite(Streamencoder.java:271) at sun.nio.Cs.StreamEncoder.write(Streamencoder.java:125) at java.io.Outputstreamwriter.write(Outputstreamwriter.java:207) at java.io.Bufferedwriter.flushBuffer(Bufferedwriter.java:129) at java.io.Printstream.write(Printstream.java:526) at java.io.Printstream.print(Printstream.java:669) at java.io.Printstream.println(Printstream.java:806) at org.hibernate.engine.jdbc.spi.SqlStatementLogger.logStatement(Sqlstatementlogger.java:111) at org.hibernate.engine.jdbc.spi.SqlStatementLogger.logStatement(Sqlstatementlogger.java:94) at org.hibernate.engine.jdbc.Internal.Statementpreparerimpl$Statementpreparationtemplate.prepareStatement(Statementpreparerimpl.java:181) at org.hibernate.engine.jdbc.Internal.StatementPreparerImpl.prepareQueryStatement(Statementpreparerimpl.java:160) at org.hibernate.Loader.plan.exec.internal.Abstractloadplanbasedloader.prepareQueryStatement(Abstractloadplanbasedloader.java:257) at org.hibernate.Loader.plan.exec.internal.Abstractloadplanbasedloader.executeQueryStatement(Abstractloadplanbasedloader.java:201) at org.hibernate.Loader.plan.exec.internal.Abstractloadplanbasedloader.executeLoad(Abstractloadplanbasedloader.java:137) at org.hibernate.Loader.plan.exec.internal.Abstractloadplanbasedloader.executeLoad(Abstractloadplanbasedloader.java:102) at org.hibernate.Loader.entity.plan.AbstractLoadPlanBasedEntityLoader.load(Abstractloadplanbasedentityloader.java:186) at org.hibernate.persister.entity.Abstractentitypersister.load(Abstractentitypersister.java:4126) at org.hibernate.Event.internal.Defaultloadeventlistener.loadFromDatasource(Defaultloadeventlistener.java:503) at org.hibernate.Event.internal.Defaultloadeventlistener.doLoad(Defaultloadeventlistener.java:468) at org.hibernate.Event.internal.Defaultloadeventlistener.load(Defaultloadeventlistener.java:213) at org.hibernate.Event.internal.Defaultloadeventlistener.proxyOrLoad(Defaultloadeventlistener.java:275) at org.hibernate.Event.internal.Defaultloadeventlistener.onload(Defaultloadeventlistener.java:151) at org.hibernate.Internal.SessionImpl.fireLoad(Sessionimpl.java:1106) at org.hibernate.Internal.SessionImpl.internalLoad(Sessionimpl.java:1025) at org.hibernate.type.EntityType.resolveIdentifier(Entitytype.java:716) at org.hibernate.type.EntityType.resolve(Entitytype.java:502) at org.hibernate.engine.internal.Twophaseload.doInitializeEntity(Twophaseload.java:170) at org.hibernate.engine.internal.Twophaseload.initializeEntity(Twophaseload.java:144) at org.hibernate.Loader.plan.exec.process.Internal.AbstractRowReader.performTwoPhaseLoad(Abstractrowreader.java:244) at org.hibernate.Loader.plan.exec.process.Internal.AbstractRowReader.finishUp(Abstractrowreader.java:215) at org.hibernate.Loader.plan.exec.process.Internal.ResultSetProcessorImpl.extractResults(Resultsetprocessorimpl.java:140) at org.hibernate.Loader.plan.exec.internal.Abstractloadplanbasedloader.executeLoad(Abstractloadplanbasedloader.java:138) at org.hibernate.Loader.plan.exec.internal.Abstractloadplanbasedloader.executeLoad(Abstractloadplanbasedloader.java:102) at org.hibernate.Loader.entity.plan.AbstractLoadPlanBasedEntityLoader.load(Abstractloadplanbasedentityloader.java:186) at org.hibernate.persister.entity.Abstractentitypersister.load(Abstractentitypersister.java:4126) at org.hibernate.Event.internal.Defaultloadeventlistener.loadFromDatasource(Defaultloadeventlistener.java:503) at org.hibernate.Event.internal.Defaultloadeventlistener.doLoad(Defaultloadeventlistener.java:468) at org.hibernate.Event.internal.Defaultloadeventlistener.load(Defaultloadeventlistener.java:213) at org.hibernate.Event.internal.Defaultloadeventlistener.proxyOrLoad(Defaultloadeventlistener.java:275) at org.hibernate.Event.internal.Defaultloadeventlistener.onload(Defaultloadeventlistener.java:151) at org.hibernate.Internal.SessionImpl.fireLoad(Sessionimpl.java:1106) at org.hibernate.Internal.SessionImpl.internalLoad(Sessionimpl.java:1025)
Some solution?
The error has something else relevant?
– Roknauta
@Douglas now put part of the error log if you have to assist me would appreciate
– Tiago Ferezin
Running the debug I noticed was on getResultList medoto()
– Tiago Ferezin
It seems to me that your array has burst, rather than like, test using a =.
– Roknauta
@Douglas and when it is not with normal wheel like
– Tiago Ferezin
@Douglas tested with
=.
as indicated and not accepted.
points error ofunexpected token:
– Tiago Ferezin
The "." was the end of the sentence, rsrs. It’s just the = same.
– Roknauta
@Douglas I need the like, because the attribute would not only be that, it would be more complete, I would need the objects that contain at the beginning of idAltective to String above so step as
"1*casa-aberta" + "%"
that had turned"1*casa-aberta%"
, got it.– Tiago Ferezin
I understand, I’ll look. Anything I put.
– Roknauta
Let’s go continue this discussion in chat.
– Tiago Ferezin