Value '0000-00-00' can not be represented as java.sql.Date

0

I need to get a table named 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

In the output of the outputs I have the following:

==== Month ===== Wed Jul 21 18:35:16 BRT 1999 ==== Month ===== Mon Jun 21 18:35:16 BRT 1999 ==== Month ===== Fri May 21 18:35:16 BRT 1999 ==== Month ===== Tue Jul 21 18:35:16 BRT 1998

but when saving the following error occurs:

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
    
asked by anonymous 19.06.2017 / 18:54

1 answer

0

Hello, this exception occurs because you're apparently trying to insert a date with zeros. And there is no date with zeros, so the error.

Do the following, in your url add the zeroDateTimeBehavior property. She should avoid the exception.

jdbc:mysql://localhost:3306/dbname?zeroDateTimeBehavior=convertToNull
    
19.06.2017 / 19:20