我正在使用MySQL数据库。我正在使用Spring Boot JPA并使用JPQL创建查询。
@Query(value="SELECT DISTINCT c FROM Category c WHERE c.distributorId " +
"IN (SELECT DISTINCT d.distributorId FROM Distributor d WHERE d.partnerId=?1)")
List<Category> findDistinctByPartnerId(long partnerId);
除了服务器(当然)之外,它还可以正常工作。问题是,它启动了服务器(意思是,确实正确加载了Entity类),但是查询响应以下错误:
ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-1) Table 'exampleDb.category' doesn't exist
我从未将数据库名称添加到实体中,甚至在调试sql中也没有显示:
Hibernate: select distinct category0_.CategoryId as Category1_5_, category0_.CatalogCode as CatalogC2_5_, category0_.CategoryName as Category3_5_, category0_.DistributorId as Distribu4_5_, category0_.ParentId as ParentId5_5_ from category categor
y0_ where category0_.DistributorId in (select distinct distributo1_.DistributorID from distributor distributo1_ where distributo1_.PartnerId=?)
我一直在寻找对此的回应,但无济于事。 预先感谢您的所有帮助!
类别:
@Entity
@Builder(toBuilder = true)
@AllArgsConstructor(access = AccessLevel.PACKAGE)
@NoArgsConstructor(access = AccessLevel.PACKAGE)
@Setter(value = AccessLevel.PUBLIC)
@Getter
@Table(name="category")
public class Category implements Serializable {
@Id
@Column(name="CategoryId")
@GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid", strategy = "uuid")
String categoryId;
@Column(name="CategoryName")
String categoryName;
@Column(name="CatalogCode")
String catalogCode;
@ManyToOne
@LazyCollection(LazyCollectionOption.FALSE)
@JoinColumn(name = "ParentId", referencedColumnName = "CategoryId")
@OnDelete(action = OnDeleteAction.CASCADE)
Category parent;
// @OneToOne
// @LazyCollection(LazyCollectionOption.FALSE)
// @JoinColumn(name = "DistributorId", referencedColumnName = "DistributorId")
// Distributor distributor;
@Column(name="DistributorId")
Long distributorId;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Category category = (Category) o;
return categoryId.equals(category.categoryId) &&
Objects.equals(categoryName, category.categoryName) &&
Objects.equals(parent, category.parent) &&
distributorId.equals(category.distributorId);
}
@Override
public int hashCode() {
return Objects.hash(categoryId, categoryName, distributorId);
}
}
通过JNDI连接:
spring.datasource.jndi-name=java:/jdbc/mapper
spring.datasource.hikari.pool-name=mapper
答案 0 :(得分:0)
正如异常所示,数据库表不存在,您可以尝试在application.properties中插入条目,例如spring.jpa.hibernate.ddl-auto=update
。
也许,您的数据库没有该表,并且您的应用程序在启动时假设该表存在于数据库中。
如果不是这种情况,那么可以请您共享服务器启动时间日志,这将有助于进一步调试此行为的原因。谢谢!