我有一个非常简单的查询,它根据"in"子句检索值.作为"in"参数出现的列表被适当地排序.
查询:
@Query(value = "select i from ItemEntity i where i.secondaryId in :ids")
List<ItemEntity> itemsIn(@Param("ids") List<UUID> ids, Pageable pageable);
Run Code Online (Sandbox Code Playgroud)
我需要以相同的方式订购结果List<UUID> ids,是否可以在没有普通sql的情况下实现这一点,但只能在Spring Data和/或的帮助下实现Hibernate.
我有自定义下面的实体,AttributeConverter它将数据库中的字段保存为二进制数据.
TaskEntity.java
@Entity
@Table(name = "task")
public class TaskEntity {
@Id
@GeneratedValue
@Column(name = "id", nullable = false)
private UUID id;
@Column(name = "state_machine_context")
@Convert(converter = StateMachineContextConverter.class)
private StateMachineContext<State, Event> stateMachineContext;
}
Run Code Online (Sandbox Code Playgroud)
StateMachineContextConverter.java
@Converter
public class StateMachineContextConverter
implements AttributeConverter<StateMachineContext, byte[]> {
private static final ThreadLocal<Kryo> kryoThreadLocal = ThreadLocal.withInitial(() -> {
Kryo kryo = new Kryo();
kryo.addDefaultSerializer(StateMachineContext.class, new StateMachineContextSerializer());
kryo.addDefaultSerializer(MessageHeaders.class, new MessageHeadersSerializer());
kryo.addDefaultSerializer(UUID.class, new UUIDSerializer());
return kryo;
});
private static final int BUFFER_SIZE = 4096;
private static final int …Run Code Online (Sandbox Code Playgroud) 我正在使用Spring Boot并WebSecurityConfigurerAdapter配置安全性。
配置被忽略的安全性antMatches的方法如下所示:
@Override
public void configure(final WebSecurity web) {
web
.ignoring()
.antMatchers("/items")
.antMatchers("/items/{itemId}")
Run Code Online (Sandbox Code Playgroud)
{itemId}UUID格式在哪里
问题是,这种配置端点喜欢/items/report,/items/images也被打开,但他们不应该。
有没有办法将忽略规则仅应用于具有路径变量的uri?
我有Postgres JSONB对象数组,看起来像这样:
'[
{
"skillId": "1",
"skillLevel": 42
},
{
"skillId": "2",
"skillLevel": 41
}
]'
Run Code Online (Sandbox Code Playgroud)
这个JSONB是一个函数参数.
什么是检索最有效的方式skillLevel进行 skillId = "1".
我试过玩,jsonb_array_elements但到目前为止我所做的一切看起来都非常混乱.
我正在为Spring Boot应用程序和Postgres DB配置JDBC连接池,以使用HikariCP连接池,并试图找到配置设置的最佳实践,不幸的是,网络上没有关于此主题的太多信息。
我正在为不同的设置准备自己的性能测试,但是希望对您有所帮助。应用程序节点的平均吞吐量约为20 req / sec
我对这些属性的最佳值最感兴趣:
minimumIdle: ?
maximumPoolSize: ?
idleTimeout: ?
maxLifetime: ?
connectionTimeout: ?
Run Code Online (Sandbox Code Playgroud)
知道最适合的值特别好maximumPoolSize
。连接池设置还有许多其他可用的选项,不胜感激关于它们对应用程序性能的影响的任何建议。
我有一张这样的地图,其中有数百万个条目:
private final Map<String, SomeItem> tops = new HashMap<>();
Run Code Online (Sandbox Code Playgroud)
我需要获取值列表,这可以通过调用 java.util.Map values()方法来完成。
每次调用方法时都会Collection创建值values(),还是从性能角度预先计算值?
由于我Map有几百万个元素,我不想每次values()调用时都创建新的列表对象。
有多种方法可以忽略 mapstruct 中未映射的目标属性。
@Mapping(target = "propName", ignore = true)
Run Code Online (Sandbox Code Playgroud)
@Mapper(
unmappedTargetPolicy = ReportingPolicy.IGNORE
)
Run Code Online (Sandbox Code Playgroud)
有没有办法混合这些方法并忽略方法级别的所有属性而不明确列出所有属性?
有两个线程,每个线程绑定两个事务:
DEBUG o.s.orm.jpa.JpaTransactionManager - Creating new transaction with name [com.workflow.consumer.RecordEventConsumer$MockitoMock$1882263982.handleRecordsAddedEvent]: PROPAGATION_REQUIRED,ISOLATION_READ_UNCOMMITTED; ''
Creating new transaction with name [com.workflow.statemachine.action.CreateContentAction.execute]: PROPAGATION_REQUIRED,ISOLATION_READ_UNCOMMITTED; ''
两个隔离级别都是READ_UNCOMMITTED。但是当第一个线程在数据库中插入一些内容时
repository.saveAndFlush(contextObject)
Run Code Online (Sandbox Code Playgroud)
存储库在哪里JpaRepository<T, I> repository
并且有插入发生的实际日志DEBUG org.hibernate.SQL - insert into task_unit ...etc
来自第二个线程的事务仍然无法检索这个对象:
repository.getOne(id);
repository.findOne(id);
entityManager.find(class, id);
Run Code Online (Sandbox Code Playgroud)
不仅如此,我还尝试直接连接到数据库并启动
BEGIN TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
SELECT * from task_unit
Run Code Online (Sandbox Code Playgroud)
但仍然没有成功。
我错过了什么吗?
我正在尝试在 SpringData 本机查询中使用 Postgres jsonb 字符串存在运算符。
SpringData 方法示例:
@Query(value = "SELECT t.id \n"
+ " FROM task AS t \n"
+ " WHERE (t.worker_ids \\? :workerId)\n"
+ " ORDER BY t.created_at\n",
nativeQuery = true)
Optional<String> findMatchingTaskId(@Param("workerId") String workerId);
Run Code Online (Sandbox Code Playgroud)
哪里worker_ids是数据库类型JSOB的。我试图排除问号,\\但仍然出现以下错误:
org.postgresql.util.PSQLException: No value specified for parameter 2.
有没有办法将此运算符与 spring 数据本机查询一起使用?
java ×6
hibernate ×4
spring-data ×4
postgresql ×3
spring ×3
spring-boot ×2
collections ×1
dictionary ×1
hashmap ×1
hikaricp ×1
jpql ×1
jsonb ×1
mapstruct ×1
performance ×1
sql ×1
transactions ×1