如果JPA项目中有两个不同包下拥有相同的实体类,且都标记了@Entity注解,会报如下异常:
Caused by: org.springframework.dao.DataAccessResourceFailureException: Could not create JPA EntityManager; nested exception is org.hibernate.DuplicateMappingException: The [xxx.xx.xx.xxxxx] and [xxx.xx.xx.xxxxx] entities share the same JPA entity name: [xxxxx] which is not allowed!
Caused by: org.hibernate.DuplicateMappingException: The [xxx.xx.xxxxx] and [xxx.xx.xx.xxxxx] entities share the same JPA entity name: [xxxxx] which is not allowed!
解决方案:
@entity(name="xxx")添加name属性
例:
@Entity(name = "test_2022")
@Table(name = "test_2022")
public class Test {}