Can GORM be used with Spring Data JPA and Rest?

I am a bit new to the "Groovy" world and have just started working with the language to understand the syntax and characteristics. I've worked a lot with Java and Spring Boot before, and since the latter is supported by Pivotal and Groovy and Grails, I wondered if Groovy could be used without problems with Spring Boot.

Well it works (obviously), but when I discovered the GORM and DSL syntax around it, I started using it. Unfortunately this doesn't seem to be the case with Spring Data JPA and Rest as I was trying to do something like this:

@grails.persistence.Entity
class Person {
    BigInteger id
    String firstName
    String lastName

    static mapping { table name: 'people' }
    static constraints { /* whatever */ }
}

@RepositoryRestResource(collectionResourceRel = "people", path = "/api/people")
interface PersonRepository extends JpaRepository<Person, BigInteger> { }

      

However Spring Boot cannot start as it throws an exception with the following expression

IllegalArgumentException: Not a managed bean Person

      

On the other hand, if I fix this Entity with JPA annotations (by removing the Grails annotation) I have no problem at all.

Is there any solution? Is it possible to somehow use GORM with Spring Data JPA and Rest, since GORM relies on Hibernate anyway?

+3


source to share


1 answer


You need to define the hibernate.packages property in application.properties or application.yml with the path to the entity package. Example:



database:
  driver: org.postgresql.Driver
  url: jdbc:postgresql://localhost:5432/retail
  username: postgres
  password: postgres
hibernate:
  packages: ru.rd.core.analytic.dto.jpa
  dialect: org.hibernate.dialect.PostgreSQL94Dialect
  show_sql: true
  hbm2ddl.auto: validate #none validate create-drop update

      

0


source







All Articles