休眠规范不使用参数SQL Server

时间:2019-02-18 16:41:07

标签: java spring hibernate

我写了一个自定义谓词,可在const defaultApolloOptions = { watchQuery: { fetchPolicy: 'network-only', errorPolicy: 'ignore', }, query: { fetchPolicy: 'network-only', errorPolicy: 'all', }, } export default class App extends Component { displayName = App.name; client = new ApolloClient({ uri: "https://localhost:44360/graphql", cache: new InMemoryCache(), defaultOptions: defaultApolloOptions }); //...render method, route definitions, etc } 查询中使用。为该查询生成的SQL不使用参数,因此查询缓存具有2个条目(因为查询相差1个字符!)。使用聚合函数是什么导致我看到的差异? (下面概述)。

我的应用程序将sqlserver 2012用于其数据库,并且我已通过sqlserver Management Studio监视了查询。我观察到的输出使用了JpaSpecificationExecutorbillingType的参数,但没有使用recordedDate的参数。

以下是我使用的谓词代码:

recordedValue

这将导致2个生成的查询,相差1个字符。 例如。 (在总部) Subquery<Entity> subQuery = query.subquery(Entity.class); Root<Entity> subQueryRoot = subQuery.from(Entity.class); subQuery.select(subQueryRoot.get("userId")); Optional<Predicate> teamEquals = // Call to helper Predicate isMinutes = builder.equal(subQueryRoot.get("billingType"), BillingType.MINUTES); Predicate minutesDate = builder.greaterThan(subQueryRoot.get("recordedDate"), LocalDate.now().minus(Period.parse(params.getHoursPeriod()))); Predicate minutesThreshold = builder.greaterThan( subQueryRoot.get("recordedValue"), params.getHours() * 60 ); Predicate minutesRestriction = builder.and(isMinutes, minutesDate, minutesThreshold); Predicate isDocuments = builder.equal(subQueryRoot.get("billingType"), BillingType.DOCUMENTS); Predicate documentsDate = builder.greaterThan(subQueryRoot.get("recordedDate"), LocalDate.now().minus(Period.parse(params.getDocumentsPeriod()))); Predicate documentsThreshold = builder.greaterThan( subQueryRoot.get("recordedValue"), params.getDocuments() ); Predicate documentsRestriction = builder.and(isDocuments, documentsDate, documentsThreshold); subQuery.where( builder.and(teamEquals.get(), builder.or( minutesRestriction, documentsRestriction ) ) ); return Optional.of(subQuery); SELECT * FROM User where id IN (SELECT userId FROM Entity WHERE billingType = @p1 AND recordedDate > @p2 AND recordedValue > 0)

1 个答案:

答案 0 :(得分:1)