Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet

Bom dia, me ajudem com essa exception?

WARN: SQL Error: 1055, SQLState: 42000
jun 09, 2022 11:44:16 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'loja.itens1_.quantidade' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
    at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154)
    at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1602)
    at org.hibernate.query.Query.getResultList(Query.java:165)
    at br.com.alura.loja.dao.PedidoDao.relatorioDeVendas(PedidoDao.java:41)
    at br.com.alura.loja.testes.CadastroDePedido.main(CadastroDePedido.java:47)
Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
    at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63)
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:67)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:2304)
    at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2057)
    at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2019)
    at org.hibernate.loader.Loader.doQuery(Loader.java:948)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:349)
    at org.hibernate.loader.Loader.doList(Loader.java:2850)
    at org.hibernate.loader.Loader.doList(Loader.java:2832)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2664)
    at org.hibernate.loader.Loader.list(Loader.java:2659)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:506)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:400)
    at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:219)
    at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1414)
    at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1625)
    at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1593)
    ... 3 more
Caused by: java.sql.SQLSyntaxErrorException: Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'loja.itens1_.quantidade' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
    at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:916)
    at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:972)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:57)
    ... 18 more

CadastroDePedido:

public class CadastroDePedido {
    public static void main(String[] args) {
    popularBancoDeDados(); 
    EntityManager em = JPAUtil.getEntityManager();
    ProdutoDao produtoDao = new ProdutoDao(em);
    ClienteDao clienteDao = new ClienteDao(em);

    Produto produto = produtoDao.buscarPorId(1l);
    Cliente cliente = clienteDao.buscarPorId(1l);

    em.getTransaction().begin();

    Pedido pedido = new Pedido(cliente); 
    pedido.adicionarItem(new ItemPedido(10, pedido, produto));

    PedidoDao pedidoDao = new PedidoDao(em);
    pedidoDao.cadastrar(pedido);//estou salvando apenas o pedido

    em.getTransaction().commit();

    BigDecimal totalVendido = pedidoDao.valorTotalVendido();
    System.out.println("VALOR TOTAL: " + totalVendido);

    List<Object[]> relatorio = pedidoDao.relatorioDeVendas();
    for (Object[] obj : relatorio) {
        System.out.println(obj[0]);
        System.out.println(obj[1]);
        System.out.println(obj[2]);
        }
    }

[...] //SUPRIMI PARA CABER...
1 resposta