Olá,
Ao executar o passo a passo da aula, obtive a seguinte exception:
java.lang.IllegalArgumentException: org.hibernate.QueryException: could not resolve property: tipoPreco of: component[tipo,valor] [select sum(preco.valor) from br.com.casadocodigo.loja.models.Produto p join fetch p.precos preco where preco.tipoPreco = :tipoPreco]
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1750)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1683)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:350)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:289)
at com.sun.proxy.$Proxy32.createQuery(Unknown Source)
at br.com.casadocodigo.loja.dao.ProdutoDao.somaPrecosPorTipo(ProdutoDao.java:43)
Agora é a query do Hibernate que tá errada. Antes dava nullpointerException no BigDecimal.class.
Meu metodo do ProdutoDAO.java
public BigDecimal somaPrecosPorTipo(TipoPreco tipoPreco) {
TypedQuery<BigDecimal> query = manager.createQuery("select sum(preco.valor) from Produto p join fetch p.precos preco where preco.tipoPreco = :tipoPreco", BigDecimal.class);
query.setParameter("tipoPreco", tipoPreco);
return query.getSingleResult();
}