【问题标题】:Spring Data JPA + EclipseLink in OracleOracle 中的 Spring Data JPA + EclipseLink
【发布时间】:2021-03-13 11:54:09
【问题描述】:

我有这个仓库:

@Repository
public interface EnvaRepository extends JpaRepository<Enva, Long> {
}

这个查询:

 envaRepository.findAllById(lopn.getEnvans());

但是在控制台我有这个错误:

SELECT t0.PERSONNE_ID, t0.DT_NAISSANCE, t1.PERSONNE_ID FROM PERSONNE t0, ENVA t1
WHERE ((t0.PERSONNE_ID IN ((777,777))) AND (t1.PERSONNE_ID = t0.PERSONNE_ID));

[42000][907] ORA-00907: parenthèse de droite absente

我的配置类:

@Configuration
public class JpaConfiguration extends JpaBaseConfiguration {

    protected JpaConfiguration(DataSource dataSource, JpaProperties properties, ObjectProvider<JtaTransactionManager> jtaTransactionManager, ObjectProvider<TransactionManagerCustomizers> transactionManagerCustomizers) {
        super(dataSource, properties, jtaTransactionManager, transactionManagerCustomizers);
    }

    @Override
    protected AbstractJpaVendorAdapter createJpaVendorAdapter() {
        log.debug("Using EclipseLinkJpaVendorAdapter");
        return new EclipseLinkJpaVendorAdapter();
    }

    @Bean
    @Primary
    public static JpaProperties properties() {
        final JpaProperties jpaProperties = new JpaProperties();
        jpaProperties.setShowSql(true);
        jpaProperties.setDatabasePlatform("org.eclipse.persistence.platform.database.OraclePlatform");
        return jpaProperties;
    }

    @Override
    protected Map<String, Object> getVendorProperties() {
        HashMap<String, Object> map = new HashMap<>();
        map.put(PersistenceUnitProperties.WEAVING, detectWeavingMode());
        return map;
    }

    private String detectWeavingMode() {
        return InstrumentationLoadTimeWeaver.isInstrumentationAvailable() ? "true" : "static";
    }
}

【问题讨论】:

  • spring 是如何构建 JPQL 查询的?它需要使用“ .. in :variable ”而不是将集合变量包装在括号中才能工作。
  • 你能分享你的 Enva 实体吗?您是否调用了除此之外的任何其他查询?

标签: sql oracle spring-boot spring-data-jpa eclipselink


【解决方案1】:
@Query("SELECT e FROM Enva e where e.personneId IN :envantIds")
    List<Enva> findAllById(Iterable<Long> envantIds);

【讨论】:

    【解决方案2】:

    像这样去掉 IN 语句中的额外括号:

    SELECT t0.PERSONNE_ID, t0.DT_NAISSANCE, t1.PERSONNE_ID 
    FROM PERSONNE t0, ENVA t1
    WHERE ((t0.PERSONNE_ID IN (777,777)) 
    AND (t1.PERSONNE_ID = t0.PERSONNE_ID));
    

    【讨论】:

    • 查询是自动为 EclipseLink 构建的
    • 我对 EclispeLink 不熟悉,但也许某处有配置,或者它可能是一个真正的错误!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-30
    • 2023-03-30
    • 2014-12-22
    • 2018-02-02
    • 2019-02-03
    • 2013-08-14
    • 2023-03-14
    相关资源
    最近更新 更多