Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

Erro de mapping de listaNotas

mesmo concluindo o mapeamento do Entity continuo recebendo o erro:

nov. 28, 2023 6:32:31 PM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing PersistenceUnitInfo [name: alugames]
nov. 28, 2023 6:32:31 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate ORM core version 5.5.7.Final
nov. 28, 2023 6:32:31 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
nov. 28, 2023 6:32:31 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
nov. 28, 2023 6:32:31 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.mysql.cj.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/alugames]
nov. 28, 2023 6:32:31 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {password=****, user=root}
nov. 28, 2023 6:32:31 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
nov. 28, 2023 6:32:31 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
nov. 28, 2023 6:32:31 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
nov. 28, 2023 6:32:32 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PoolState stop
INFO: HHH10001008: Cleaning up connection pool [jdbc:mysql://localhost:3306/alugames]
Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: alugames] Unable to build Hibernate SessionFactory
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1495)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1415)
    at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:56)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
    at br.com.techv.alugames.dados.Banco.getEntityManager(Banco.kt:22)
    at br.com.techv.alugames.dados.JogoDAO.getJogos(JogoDAO.kt:8)
    at br.com.techv.alugames.principal.InsertBancoKt.main(insertBanco.kt:11)
    at br.com.techv.alugames.principal.InsertBancoKt.main(insertBanco.kt)
Caused by: org.hibernate.MappingException: Could not determine type for: java.util.List, at table: jogos, for columns: [org.hibernate.mapping.Column(listaNotas)]
    at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:512)
    at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:479)
    at org.hibernate.mapping.Property.isValid(Property.java:227)
    at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:625)
    at org.hibernate.mapping.RootClass.validate(RootClass.java:267)
    at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:354)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:307)
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:471)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1410)
    ... 7 more

Process finished with exit code 1
class JogoDAO {

    fun getJogos(): List<Jogo>{
        val manager = Banco.getEntityManager()
        try {
            val query = manager.createQuery("FROM JogoEntity", JogoEntity::class.java)
            return query.resultList.map { a -> Jogo(a.titulo,
                                                    a.capa,
                                                    a.descricao,
                                                    a.preco,
                                                    a.id) }
        } finally {
            manager.close()
        }
    }
    }
@Entity
@Table(name="jogos")
class JogoEntity(
    val titulo: String = "Titulo do jogo",
    val capa: String = "Capa do jogo",
    val descricao: String? = null,
    val preco: Double = 0.0,

    @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
    val id: Int = 0) {
}
2 respostas
solução!

Consegui resolver, não tinha ficado claro pra mim que o mapeamento de Jogo.kt devia ser desfeito

Oii, Vinicius! Tudo bem?

Obrigada por compartilhar conosco a solução do seu bug! Assim você pode ajudar outra pessoa caso ela precise.

Se outra dúvida surgir, estamos aqui.

Abraços!