简体   繁体   English

获取 entityManageFactory 错误。 模式验证:缺少表 [hibernate_sequence]

[英]Getting entityManageFactory error. Schema-validation: missing table [hibernate_sequence]

I have 2 databases.我有 2 个数据库。 One is set up and and it works.一个已设置并且可以正常工作。 After I add second db I am having following error entityManageFactory error.添加第二个数据库后,出现以下错误 entityManageFactory 错误。 Schema-validation: missing table [hibernate_sequence].模式验证:缺少表 [hibernate_sequence]。

My db schema looks like this: db schema screenshot我的 db 架构如下所示: db schema screenshot

在此处输入图像描述

I have two classes for two tables:我有两个表的两个类:

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Entity(name = "nightly_rate_amounts")
@Table(name = "nightly_rate_amounts")
public class BookedNightlyRate {
@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "bnr_meta_id")
    private Long id;
    @Column(name = "unit_uuid")
    private UUID unitUuid;
    private LocalDate firstLiveDate;
    private LocalDate date;
    private BigDecimal amount;
    @Column(name = "currency_code")
    private String currencyCode;

    public ImmutableTriple<UUID, LocalDate, String> toUnitDateCurrencyKey() {
        return new ImmutableTriple<>(unitUuid, date, currencyCode);
    }

    public ImmutablePair<UUID, String> toUnitCurrencyKey() {
        return new ImmutablePair<>(unitUuid, currencyCode);
    }
}

and:和:

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Entity(name = "unit_attributes")
@Table(name = "unit_attributes")
public class BookedUnitAttributes {
    @Id
    @Column(name = "unit_uuid")
    private UUID unitUuid;
    @Column(name = "first_date_available")
    private LocalDate firstLiveDate;
}

and Repository files:和存储库文件:

public interface BookedNightlyRatesDao extends CrudRepository<BookedNightlyRate, Long> {

@Query(value = "SELECT DISTINCT bnr.unit_uuid as unitUuid, bnr.date, bnr.amount, bnr.currency_code as currencyCode " +
        "FROM nightly_rate_amounts AS bnr " +
        "WHERE bnr.unit_uuid IN (<unitUuids>) AND (bnr.date BETWEEN :fromDate AND :toDate)", nativeQuery = true)
List<BookedNightlyRate> findBookedNightlyRates(@Param("unitUuids") List<String> unitUuids, @Param("fromDate") LocalDate fromDate, @Param("toDate") LocalDate toDate);

@Query(value = "SELECT DISTINCT opb.unit_uuid as unitUuid, opb.date, opb.amount, opb.currency_code as currencyCode " +
        "FROM opb_nightly_rate_amounts AS opb " +
        "JOIN opb_sync_enabled_for_unit AS sync ON opb.unit_uuid = sync.unit_uuid WHERE sync.enabled = 1 AND opb.is_active = 1 " +
        "AND sync.unit_uuid IN (<unitUuids>) AND (opb.date BETWEEN :fromDate AND :toDate)", nativeQuery = true)
List<BookedNightlyRate> findOPBRates(@Param("unitUuids") List<String> unitUuids, @Param("fromDate") LocalDate fromDate, @Param("toDate") LocalDate toDate);
}

second interface:第二个界面:

public interface BookedUnitAttributesDao extends CrudRepository<BookedUnitAttributes, UUID> {

@Query(value = "SELECT ua.unit_uuid as unitUuid, ua.first_date_available as firstLiveDate " +
        "FROM unit_attributes AS ua " +
        "WHERE ua.unit_uuid IN (<unitUuids>)", nativeQuery = true)
List<BookedUnitAttributes> findUnitAttributes(@Param("unitUuids") List<String> unitUuids);
}

I am rewriting my db from jdbi to jpa.我正在将我的数据库从 jdbi 重写为 jpa。 So Data classes didn't have any annotations and I refactored my model files regarding it queries in repository files.所以数据类没有任何注释,我重构了我的 model 文件,因为它在存储库文件中查询。

Since you add two database Spring dosn't know what kind of database it connect.由于您添加了两个数据库 Spring 不知道它连接什么样的数据库。 You have to exactly showed what kind of database you want to connect.您必须准确显示要连接的数据库类型。 You might confiugure connection with two different database here is example of working with JdbcTemplate connection.您可能会配置与两个不同数据库的连接,这里是使用 JdbcTemplate 连接的示例。

@Configuration
@ComponentScan("uz.dbo.dbocallcenter")
@PropertySource("classpath:database.properties")
public class Config2 {

    @Autowired
    Environment environment;

    private final String DRIVER = "driver";
    private final String URL1 = "url1";
    private final String USER1 = "dbusername1";
    private final String PASSWORD1 = "dbpassword1";
    private final String URL2 = "url2";
    private final String USER2 = "dbusername2";
    private final String PASSWORD2 = "dbpassword2";


    private DataSource dataSource1() {
        return getDataSource(URL1, USER1, PASSWORD1);
    }
    private DataSource dataSource2() {
        return getDataSource(URL2, USER2, PASSWORD2);
    }

    private DataSource getDataSource(String url1, String user1, String password1) {
        DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource();
        driverManagerDataSource.setUrl(environment.getProperty(url1));
        driverManagerDataSource.setUsername(environment.getProperty(user1));
        driverManagerDataSource.setPassword(environment.getProperty(password1));
        driverManagerDataSource.setDriverClassName(environment.getProperty(DRIVER));
        return driverManagerDataSource;
    }




    @Bean(name = "jdbcTemplate2")
    public JdbcTemplate jdbcTemplate2() {
        return new JdbcTemplate(dataSource2());
    }
    @Bean(name = "jdbcTemplate1")
    public JdbcTemplate jdbcTemplate1() {
        return new JdbcTemplate(dataSource1());
    }

}

you have to do with JpaRepository connection.您必须与 JpaRepository 连接有关。 More precisely you can gain knowledge about this source更准确地说,您可以获得有关此来源的知识

https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#reference https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#reference

Here is also good explanation how to connect two differnet database in one spring boot project这里也很好地解释了如何在一个 spring 引导项目中连接两个不同的数据库

https://www.baeldung.com/spring-data-jpa-multiple-databases https://www.baeldung.com/spring-data-jpa-multiple-databases

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Boot 项目由于 Schema-validation 无法运行:缺少序列 [hibernate_sequence] - Spring Boot project fails to run because of Schema-validation: missing sequence [hibernate_sequence] Java Spring Hibernate Schema-Validation:缺少表 - Java Spring Hibernate Schema-Validation: Missing Table 架构验证:缺少表 [hibernate_sequences] - Schema-validation: missing table [hibernate_sequences] 模式验证:使用Flyway的Hibernate生成的SQL代码缺少表[…]错误消息 - Schema-validation: missing table […] error message using flyway for a SQL code generated by Hibernate Hibernate + JPA:模式验证:缺少列 - Hibernate + JPA: Schema-validation: missing column 缺少序列或表:hibernate_sequence - Missing sequence or table: hibernate_sequence 错误:缺少表“hibernate_sequence”的 FROM 子句条目 - ERROR: missing FROM-clause entry for table "hibernate_sequence" Hibernate继承:模式验证:缺少列 - Hibernate inheritance: Schema-validation: missing column 使用Schema-validation验证除dbo结果以外的其他模式中的休眠访问表:缺少表 - Hibernate acessing table in schema other than dbo results with Schema-validation: missing table SqlServer2016,Hibernate 模式验证:缺少表,但表存在于数据库中 - SqlServer2016, Hibernate schema-validation: Missing table, but table exists in db
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM