1
I need to take a table called history the last three months and a year before to register in the product table. The code is as follows:
for (int i = prod.getHistoricos().size(); i >= 0; i--) {
if (i == prod.getHistoricos().size() - 1 || i == prod.getHistoricos().size() - 2
|| i == prod.getHistoricos().size() - 3 || i == prod.getHistoricos().size() - 13) {
mesesDoProduto.add(prod.getHistoricos().get(i).getMesesHistoricos());
}
}
for (int i = 0; i < mesesDoProduto.size(); i++) {
if (i == 0) {
prod.setPrimeiroMesAnterior(mesesDoProduto.get(i));
System.out.println("====Mes===== " + mesesDoProduto.get(i));
}
if (i == 1) {
prod.setSegundoMesAnterior(mesesDoProduto.get(i));
System.out.println("====Mes===== " + mesesDoProduto.get(i));
}
if (i == 2) {
prod.setTerceiroMesAnterior(mesesDoProduto.get(i));
System.out.println("====Mes===== " + mesesDoProduto.get(i));
}
if (i == 3) {
prod.setAnoAnterior(mesesDoProduto.get(i));
System.out.println("====Mes===== " + mesesDoProduto.get(i));
}
}
Double alfa = BigDecimal.valueOf((fatorAmortecimentoExponencial(arrayComUltimosCincoMeses)))
.setScale(3, RoundingMode.HALF_UP).doubleValue();
System.out.println("Alfa " + alfa);
System.out.println("Melhor taxa: " + alfa + " - resultado: "
+ Math.round(calculoPrevisao(alfa.doubleValue(), arrayComQuantidades)));
Long previsao = Math.round(calculoPrevisao(alfa.doubleValue(), arrayComQuantidades));
listaComCincoUltimosMeses.clear();
listaComQuantidade.clear();
mesesDoProduto.clear();
prod.setEmpresa(empresaSelecionada);
prod.setGerenteFilial(gerenteFilial);
prod.setFatorAmortecimentoExponencial(alfa);
prod.setQuantidadeRecente(previsao);
prod.setQuantidadeReais(prod.getValor().multiply(new BigDecimal(previsao)));
cadastroProdutoService.importar(prod, gerenteFilial);// persistir
// após
// calcular
On the output of outputs I have the following :
====Mes==== Wed Jul 21 18:35:16 BRT 1999 ====Mes==== = Mon Jun 21 18:35:16 BRT 1999 ====Mes==== = Fri May 21 18:35:16 BRT 1999 ====Mes==== = Tue Jul 21 18:35:16 BRT 1998
but when saving occurs the following error :
Caused by: java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Date
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:996)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:935)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:924)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:870)
at com.mysql.jdbc.ResultSetRow.getDateFast(ResultSetRow.java:131)
at com.mysql.jdbc.ByteArrayRow.getDateFast(ByteArrayRow.java:243)
at com.mysql.jdbc.ResultSetImpl.getDate(ResultSetImpl.java:2003)
at com.mysql.jdbc.ResultSetImpl.getDate(ResultSetImpl.java:1966)
at com.mysql.jdbc.ResultSetImpl.getDate(ResultSetImpl.java:2022)
at com.mchange.v2.c3p0.impl.NewProxyResultSet.getDate(NewProxyResultSet.java:2988)
at org.hibernate.type.descriptor.sql.DateTypeDescriptor$2.doExtract(DateTypeDescriptor.java:75)
at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:64)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:267)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:263)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:253)
at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:338)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2969)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1696)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1628)
at org.hibernate.loader.Loader.getRow(Loader.java:1515)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:726)
at org.hibernate.loader.Loader.processResultSet(Loader.java:953)
at org.hibernate.loader.Loader.doQuery(Loader.java:921)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:355)
at org.hibernate.loader.Loader.doList(Loader.java:2554)
... 122 more
actually should not be entering with zero because it has value.
– user2509556
But someone is trying to insert with zeros. Maybe Hibernate or Mysql Driver or C3P0. The thing is, if you use the property I gave you, it’ll solve that. Also check in your database if there is no date column with zeros there, because in the query they may result in exception. If it exists, switch to null.
– romarcio
there were columns with zeros . to the strip it worked
– user2509556