Announcement Announcement Module
No announcement yet.
@Entity package different than the Repository packge Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • @Entity package different than the Repository packge

    I'm new to Spring.
    I want to locate the @Entity classes in a different package (or even in a different module) than the @Repository classes.
    For some reason Spring fails to run if the @Entity and the @Repository classes are in different classes.
    The error I get is that the @Entity class is not managed class (what ever that's mean).
    I tried to use @ComponentScan from the repository classes to look for the entities classes, I tries to use @EnableAutoConfiguration in the @Entity classes, and in the repositories, but nothing.
    Only when I place the Entity and the Repository classes in the same class it works.

    Any idea of what happen behind the scene would be much appreciated.
    Thank you in advance

  • #2
    You need to configure your persistence layer correctly, I would recommend you look at the Spring documentation,
    the ORM-JPA section may be a good place to start (see: section 14.5 JPA)

    I would look at setting up a persistence.xml file and orm.xml file.

    I would also look at examples on GitHub under the spring projects. There is also some great getting started guides on @

    If you have more questions or need more details I would direct them to stackoverflow and add the tag "spring-data" as you will get your questions answer there as this forum is moving to Stackoverflow soon.


    • #3
      Another option is to look at the property "packagesToScan" for LocalContainerEntityManagerFactoryBean