我有两个实体Transaction
和Statement
,我正在寻找没有与之关联的语句的交易,
@SuppressWarnings("serial")
@MappedSuperclass
@ToString
@Getter
@Setter
@RequiredArgsConstructor
@EntityListeners(AuditingEntityListener.class)
abstract class Template implements Serializable, Cloneable {
@Id
@Column(unique = true)
private String id = UUID.randomUUID().toString();
.... auditing equals and hash methods here
}
@Entity
@Getter
@Setter
@RequiredArgsConstructor
class Transaction extends Template {
.... more here
@OneToOne(cascade = CascadeType.ALL, mappedBy = "transaction")
private Statement statement;
}
@Entity
@ToString
@Getter
@Setter
@RequiredArgsConstructor
class Statement extends Template {
.... more here
@OneToOne(optional = false)
private Transaction transaction;
}
@RepositoryRestResource
interface TransactionRepository extends JpaRepository<Transaction, String> {
//@Query("select transaction from Transaction transaction where statement is null ")
Collection<Transaction> findByStatementIsNull();
}
向JpaRepository提供或不提供@Query
的情况下,同一查询正在生成,这是错误的,因为它正在寻找where transactio0_.id is null
而应该寻找statement is null
select transactio0_.id as id1_45_, transactio0_.created_date as created_2_45_, transactio0_.creator as creator3_45_, transactio0_.modified_date as modified4_45_, transactio0_.modifier as modifier5_45_, transactio0_.aggregate_id as aggrega16_45_, transactio0_.amount as amount6_45_, transactio0_.billing_address_id as billing17_45_, transactio0_.blacklisted as blacklis7_45_, transactio0_.connection_id as connect18_45_, transactio0_.credit_card_id as credit_19_45_, transactio0_.currency as currency8_45_, transactio0_.customer_id as custome20_45_, transactio0_.description as descript9_45_, transactio0_.device_id as device_21_45_, transactio0_.electronic_check_id as electro22_45_, transactio0_.fraud_status as fraud_s10_45_, transactio0_.gateway_id as gateway23_45_, transactio0_.independent_sales_organization_id as indepen24_45_, transactio0_.issue_payment_id as issue_p25_45_, transactio0_.merchant_id as merchan26_45_, transactio0_.order_id as order_i11_45_, transactio0_.process_type as process12_45_, transactio0_.recurring_id as recurri27_45_, transactio0_.shipping_address_id as shippin28_45_, transactio0_.store_id as store_i29_45_, transactio0_.transaction_id as transac13_45_, transactio0_.transaction_status as transac14_45_, transactio0_.transaction_type as transac15_45_, transactio0_.wallet_account_id as wallet_30_45_
from billing_transaction transactio0_
where transactio0_.id is null
我不确定这是否是Spring Data JPA中的错误,或者我在这里做错了什么,这在Spring Boot 1.5.1.RELEASE中可以正常工作,但在升级到Spring Boot v2.0.3后出现此问题.RELEASE
spring boot v2.0.3.RELEASE依赖项是 spring-boot-starter-data-jpa 2.0.3.RELEASE hibernate.version 5.2.17.Final