3
respostas

findAll não e reconhecido em TopicoService

alem de não esta senho reconecida, tambem nao esta retonadno o Bd

@Service
class TopicoService(
    private val repository: TopicoRepository,
    private val topicoViewMapper: TopicoViewMapper,
    private val topicoFormMapper: TopicoFormMapper,
    private val notFoundMessage: String = "Dados nao encontrado!"
) {

    fun listar(
        nomeCurso: String?,
        paginacao: Pageable
    ): Page<TopicoView> {
        val topicos = if (nomeCurso == null) {
            repository.findAll(paginacao)
        } else {
            repository.findByCursoNome(nomeCurso, paginacao)
        }
        return topicos.map { t ->
            topicoViewMapper.map(t)
        }
    }

    fun buscarPorId(id: Long): TopicoView {
        val topico = repository.findById(id)
            .orElseThrow{NotFoundException(notFoundMessage)}
        return topicoViewMapper.map(topico)
    }

    fun cadastrar(form: TopicoForm): TopicoView {
        val topico = topicoFormMapper.map(form)
        repository.save(topico)
        return topicoViewMapper.map(topico)
    }

    fun atualizar(form: AtualizacaoTopicoForm): TopicoView {
        val topico = repository.findById(form.id)
            .orElseThrow{NotFoundException(notFoundMessage)}
        topico.titulo = form.titulo
        topico.mensagem = form.mensagem
        return topicoViewMapper.map(topico)
    }

    fun deletar(id: Long) {
        repository.deleteById(id)
    }

}

pegui o codigo do git da aula anterio porem rodou normal , mais , não rodou o Bd ,

apos da um build no rpojeto vem o seguite erro ..

C:\forum\src\main\kotlin\br\com\alura\forum\service\TopicoService.kt:31:24
Kotlin: None of the following functions can be called with the arguments supplied: 
public abstract fun <S : Topico!> findAll(p0: Example<TypeVariable(S)!>): (Mutable)List<TypeVariable(S)!> defined in br.com.alura.forum.repository.TopicoRepository
public abstract fun findAll(p0: Pageable): Page<Topico!> defined in br.com.alura.forum.repository.TopicoRepository
public abstract fun findAll(p0: Sort): (Mutable)List<Topico!> defined in br.com.alura.forum.repository.TopicoRepository

C:\forum\src\main\kotlin\br\com\alura\forum\service\TopicoService.kt:33:51
Kotlin: Type mismatch: inferred type is java.awt.print.Pageable but org.springframework.data.domain.Pageable was expected

Kotlin: Language version 1.4 is deprecated and its support will be removed in a future version of Kotlin
3 respostas
2023-10-09 15:17:17.443  INFO 3776 --- [  restartedMain] br.com.alura.forum.ForumApplicationKt    : Starting ForumApplicationKt using Java 17.0.7 on DESKTOP-108RCKC with PID 3776 (C:\aula3\target\classes started by Leo in C:\aula3)
2023-10-09 15:17:17.448  INFO 3776 --- [  restartedMain] br.com.alura.forum.ForumApplicationKt    : No active profile set, falling back to default profiles: default
2023-10-09 15:17:17.623  INFO 3776 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2023-10-09 15:17:17.623  INFO 3776 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2023-10-09 15:17:19.337  INFO 3776 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2023-10-09 15:17:19.513  INFO 3776 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 160 ms. Found 3 JPA repository interfaces.
2023-10-09 15:17:20.886  INFO 3776 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2023-10-09 15:17:20.908  INFO 3776 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-10-09 15:17:20.909  INFO 3776 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.44]
2023-10-09 15:17:21.046  INFO 3776 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2023-10-09 15:17:21.046  INFO 3776 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3421 ms
2023-10-09 15:17:21.141  INFO 3776 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2023-10-09 15:17:21.507  INFO 3776 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2023-10-09 15:17:21.520  INFO 3776 --- [  restartedMain] o.s.b.a.h2.H2ConsoleAutoConfiguration    : H2 console available at '/h2-console'. Database
available at 'jdbc:h2:mem:forum'
2023-10-09 15:17:21.725  INFO 3776 --- [  restartedMain] o.f.c.internal.license.VersionPrinter    : Flyway Community Edition 7.1.1 by Redgate
2023-10-09 15:17:21.786  INFO 3776 --- [  restartedMain] o.f.c.i.database.base.DatabaseType       : Database: jdbc:h2:mem:forum (H2 1.4)
2023-10-09 15:17:21.907  INFO 3776 --- [  restartedMain] o.f.core.internal.command.DbValidate     : Successfully validated 4 migrations (execution time 00:00.044s)
2023-10-09 15:17:21.925  INFO 3776 --- [  restartedMain] o.f.c.i.s.JdbcTableSchemaHistory         : Creating Schema History table "PUBLIC"."flyway_schema_history" ...
2023-10-09 15:17:22.107  INFO 3776 --- [  restartedMain] o.f.core.internal.command.DbMigrate      : Current version of schema "PUBLIC": << Empty Schema >>
2023-10-09 15:17:22.113  INFO 3776 --- [  restartedMain] o.f.core.internal.command.DbMigrate      : Migrating schema "PUBLIC" to version "1 - create table curso"
2023-10-09 15:17:22.152  INFO 3776 --- [  restartedMain] o.f.core.internal.command.DbMigrate      : Migrating schema "PUBLIC" to version "2 - create table usuario"
2023-10-09 15:17:22.179  INFO 3776 --- [  restartedMain] o.f.core.internal.command.DbMigrate      : Migrating schema "PUBLIC" to version "3 - create table topico"
2023-10-09 15:17:22.213  INFO 3776 --- [  restartedMain] o.f.core.internal.command.DbMigrate      : Migrating schema "PUBLIC" to version "4 - create table resposta"
2023-10-09 15:17:22.245  INFO 3776 --- [  restartedMain] o.f.core.internal.command.DbMigrate      : Successfully applied 4 migrations to schema "PUBLIC" (execution time 00:00.156s)
2023-10-09 15:17:22.447  INFO 3776 --- [  restartedMain] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2023-10-09 15:17:22.609  INFO 3776 --- [  restartedMain] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.4.29.Final
2023-10-09 15:17:22.905  INFO 3776 --- [  restartedMain] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2023-10-09 15:17:23.153  INFO 3776 --- [  restartedMain] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2023-10-09 15:17:23.995  INFO 3776 --- [  restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2023-10-09 15:17:24.008  INFO 3776 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2023-10-09 15:17:24.030  INFO 3776 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2023-10-09 15:17:25.329  WARN 3776 --- [  restartedMain] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2023-10-09 15:17:25.515  INFO 3776 --- [  restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2023-10-09 15:17:25.973  INFO 3776 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2023-10-09 15:17:25.991  INFO 3776 --- [  restartedMain] br.com.alura.forum.ForumApplicationKt    : Started ForumApplicationKt in 9.463 seconds (JVM running for 10.62)

esse e codigo que vem quando rodo com o codigo que baixei do git da aula 3

Oii, Leobaldo! Tudo bem?

A mensagem de aviso nos informa que o compilador não está reconhecendo o método e está mostrando um erro relacionado ao tipo de parâmetro esperado.

Isso geralmente ocorre quando há uma importação incorreta da classe Pageable. Certifique-se de que você está importando a classe correta do pacote org.springframework.data.domain.

No entanto, o erro também menciona que a versão 1.4 está obsoleta e será removida em futuras versões do Kotlin. Recomendo atualizar para uma versão mais recente para evitar outros possíveis erros.

Mais um ponto a considerar, o erro pode estar relacionado à dependência do Spring Data JPA no seu projeto. Verifique se você adicionou corretamente a dependência no seu arquivo build.gradle ou pom.xml, dependendo do gerenciador de dependências que você está utilizando.

Além disso, sugiro revisar o código do repositório TopicoRepository para garantir que o método findAll esteja implementado corretamente.

Espero que as sugestões te ajude. Continue interagindo no fórum compartilhando dúvidas, projetos e sugestões.

Bons estudos, Leobaldo!