I'm having trouble with my first steps using Spring-Boot with JPA. I've started with a pretty minimalistic example from Git using Gradle.
Now simply moving Customer
to another package, let's say to hello2
results in an exception Caused by: java.lang.IllegalArgumentException: Not an managed type: class hello2.Customer
. I tried to add
@ComponentScan(basePackageClasses= {Customer.class}) // AND OR @EnableJpaRepositories(basePackageClasses= {Customer.class})
to Application
, but without success.
What am I doing wrong?
An entity can aggregate objects together and effectively persist data and related objects using the transactional, security, and concurrency services of a JPA persistence provider.
Save and saveAndFlush both can be used for saving entities. They both are both belong to the Spring data library. save may or may not write your changes to the DB straight away. When we call saveAndFlush system are enforcing the synchronization of your model state with the DB.
The @Entity annotation specifies that the class is an entity and is mapped to a database table. The @Table annotation specifies the name of the database table to be used for mapping.
No, not possible with JPA or Hibernate. It does seem strange, when coding in the Java language which allows for attributes to be interfaces, that a persistence standard like JPA, intended for Java, does not support persisting attributes that are interfaces.
Location of entities in Spring Boot can be configured using @EntityScan
.
By default, @EnableAutoConfiguration
enables entity scanning in the package where it's placed (if it's not a default package).
You must locate entities and repositories pakages by using
@EnableJpaRepositories(basePackages = "your.repositories.pakage") @EntityScan(basePackages = "your.entities.pakage")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With