我有这样的 JPA 存储库和 JPQL 查询:
@Query("SELECT c from Campaign c" +
" left join fetch c.postsList p on p.status = :postStatus" +
" left join fetch p.platform" +
" left join fetch c.campaignStatistics stat on stat.updateDate = :updateDate" +
" where c.id =:id")
Campaign findCampaignWithPosts(
@Param("id") Long id,
@Param("postStatus") PostStatus postStatus,
@Param("updateDate") LocalDate updateDate);
Run Code Online (Sandbox Code Playgroud)
但它不起作用。我得到:
org.hibernate.hql.internal.ast.QuerySyntaxException: with-clause not allowed on fetched associations; use filters
Run Code Online (Sandbox Code Playgroud)
我去研究了有关 JPA 2.1 规范的信息,这就是我发现的:
用于连接的连接条件来自映射的连接列。这意味着 JPQL 用户通常不必知道每个关系是如何连接的。在某些情况下,需要向连接条件附加附加条件,通常是在外部连接的情况下。这可以通过 ON 子句来完成。ON 子句在 JPA 2.1 规范中定义,并且某些 JPA 提供程序可能支持。EclipseLink : …
我一直使用 RestTemplate,并决定切换到 WebClient。
在发送请求之前,我使用私钥对请求正文进行签名,然后客户端使用公钥检查请求。
我的拦截器:
private static class SignatureClientHttpRequestInterceptor implements ClientHttpRequestInterceptor {
private final PrivateKey privateKey;
private SignatureClientHttpRequestInterceptor(String privateKeyLocation) {
this.privateKey = PemUtils.getPrivateKey(Paths.get(privateKeyLocation));
}
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
if (request.getMethod() == HttpMethod.POST) {
request.getHeaders().add("X-Signature", Base64.getEncoder().encodeToString(PemUtils.signData(privateKey, SignatureAlgorithm.RS256.getJcaName(), body)));
}
return execution.execute(request, body);
}
}
Run Code Online (Sandbox Code Playgroud)
但在WebClient中我没有在ExchangeFilterFunction中找到这样的机会。
无论如何,是否可以在 WebClient 中执行此操作,或者我是否必须在发送请求正文之前手动签署请求正文?
I use AsyncHttpClient library for async non blocking requests. My case: write data to a file as it is received over the network.
For download file from remote host and save to file I used default ResponseBodyPartFactory.EAGER and AsynchronousFileChannel so as not to block the netty thread as data arrives. But as my measurements showed, in comparison with LAZY the memory consumption in the Java heap increases many times over.
So I decided to go straight to LAZY, but …
我在我的应用程序中使用Hibernate ORM和PostgreSQL,有时我使用批处理操作.起初我不明白为什么在批处理大小为25的日志中,会生成25个查询,并且最初认为它无法正常工作.但之后我查看了pg驱动程序的源代码,并在PgStatement类中找到以下行:
public int[] executeBatch() throws SQLException {
this.checkClosed();
this.closeForNextExecution();
if (this.batchStatements != null && !this.batchStatements.isEmpty()) {
this.transformQueriesAndParameters();
//confuses next line, because we have array of identical queries
Query[] queries = (Query[])this.batchStatements.toArray(new Query[0]);
ParameterList[] parameterLists =
(ParameterList[])this.batchParameters.toArray(new ParameterList[0]);
this.batchStatements.clear();
this.batchParameters.clear();
Run Code Online (Sandbox Code Playgroud)
并在PgPreparedStatement类中
public void addBatch() throws SQLException {
checkClosed();
if (batchStatements == null) {
batchStatements = new ArrayList<Query>();
batchParameters = new ArrayList<ParameterList>();
}
batchParameters.add(preparedParameters.copy());
Query query = preparedQuery.query;
//confuses next line
if (!(query instanceof BatchedQuery) || batchStatements.isEmpty()) {
batchStatements.add(query);
}
} …Run Code Online (Sandbox Code Playgroud) 我在我的网络应用程序中使用 spring 数据 jpa,我有实体用户
@Entity
public class User implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private String password;
private String email;
private Boolean enabled;
private String name;
private String lastname;
private String userRole;
public User() {
}
public User(String password, String email, Boolean enabled, String name, String lastname, String userRole) {
this.password = password;
this.email = email;
this.enabled = enabled;
this.name = name;
this.lastname = lastname;
this.userRole = userRole;
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO, …Run Code Online (Sandbox Code Playgroud) 我有一个过滤器服务,其方法是通过方面进行分析的。作为一个例子,我会给你一段我遇到问题的代码
@Service
public class FilterService extends AbstractService {
private static final Logger log = LoggerFactory.getLogger(FilterService.class);
@Autowired
//Proxy to profiling class
private FilterService self;
private final ItemsRepository itemsRepository;
private final Map<String, EnumFilter> enumFilters;
public FilterService(ReadWriteLock readWriteLock,
ItemsRepository itemsRepository,
CategoryRepository categoryRepository, ItemsMapper itemsMapper,
CharacteristicsRepository characteristicsRepository,
List<EnumFilter> enumFilters) {
super(readWriteLock.readLock());
this.itemsRepository = itemsRepository;
this.enumFilters = enumFilters.stream().collect(Collectors.toMap(EnumFilter::getId, y -> y));
}
@Profileable
public ItemsViewShared filterItems(@Nullable String categoryId,
@NotNull Set<String> ids,
@NotNull Lang lang,
@NotNull SortType sortType,
@NotNull FilterInfo filterInfo) {
try {
this.readLock.lock();
final …Run Code Online (Sandbox Code Playgroud) java ×6
hibernate ×3
jpa ×2
spring ×2
aspect ×1
asynchronous ×1
cglib ×1
jdbc ×1
join ×1
jpql ×1
nio ×1
nio2 ×1
postgresql ×1
spring-aop ×1
spring-mvc ×1