org.postgresql.util.PSQLException:错误:关系“产品”不存在

时间:2018-10-29 08:42:44

标签: java database postgresql jpa orm

我正在处理以下代码:

产品

 @Entity
 @Table(name = "products",
 public class Product extends RepresentativeModel {
 @ManyToMany(mappedBy = "products", targetEntity = Category.class)
 private Set<Category> categories = new HashSet<>();
 }

类别

 @Entity
 @Table(name = "categories",
 public class Category extends RepresentativeModel {
 @ManyToMany
@JoinTable(name = "productToCategory",
        joinColumns = {@JoinColumn(name = "categoryId")},
        inverseJoinColumns = {@JoinColumn(name = "productId")})
private Set<Product> products = new HashSet<>();
 }

EM配置

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(@Qualifier("dataSource") DataSource source) {
    LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean();
    entityManagerFactory.setDataSource(source);
    entityManagerFactory.setPackagesToScan("com.x.model");
    JpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
    entityManagerFactory.setJpaVendorAdapter(jpaVendorAdapter);
    entityManagerFactory.setJpaProperties(jpaProperties());
    entityManagerFactory.setPersistenceUnitName(PERSISTENCE_UNIT_NAME);
    log.debug("PERSISTENCE UNIT " + PERSISTENCE_UNIT_NAME);
    return entityManagerFactory;
}

包装信息

两者的

软件包均为com.x.model

Properties properties = new Properties(); 
properties.put("hibernate.default_schema", "public"); 
entityManagerFactory.setJpaProperties(properties); 

问题

产品表存在于数据库中,但是我收到此错误消息:

  

org.postgresql.util.PSQLException:错误:关系“产品”不正确   存在

我试图将实体名称更改为“ 产品”或将mappedBy更改为“ 产品”,但是没有成功。

该如何解决?

0 个答案:

没有答案