![](/img/trans.png)
[英]org.postgresql.util.PSQLException: ERROR: relation “sequence” does not exist
[英]org.postgresql.util.PSQLException: ERROR: relation "products" does not exist
我正在處理以下代碼:
產品
@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<>();
}
電磁配置
@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
更改為“產品”,但沒有成功。
如何解決這個問題?
我遇到了同樣的問題,互聯網上的所有答案都沒有幫助我。 而且我發現 postrgres 以區分大小寫的方式創建表,如果您在創建表時添加雙引號。
"auteur" and auteur are two different names.
我不確切知道它是如何工作的,但顯然 Hibernate 無法找到@JoinTable
關系的@ManyToMany
,因為正如我在上面所寫的,這是 postgres 的不同表。 知道這一點解決了我的問題。 也許這會幫助別人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.