使用 MongoRepository 时出现 StackOverflowError save/insert
StackOverflowError while using MongoRepository save/insert
我正在尝试使用 mongo 存储库将 save/insert 包装器键值 Class 放入我的 mongo 数据库中。
我要保存的模型是:
@Data
@AllArgsConstructor
@Document(collection = "futureTask")
public class FutureTask {
@Id
private Configuration configuration;
private ScheduledFuture<?> future;
}
存储库实现如下:
public interface FutureTaskRepository extends MongoRepository<FutureTask, Configuration> {
FutureTask findByConfiguration(Configuration configuration);
boolean existsByConfiguration(Configuration configuration);
}
FutureTaskRepository的调用如下:
ScheduledFuture<?> future = this.schedule(new RunnableTask(configuration), new CronTrigger(configuration.getCron()));
FutureTask futureTask = new FutureTask(configuration, future);
futureTaskRepository.insert(futureTask);
我收到以下错误:
java.lang.WhosebugError: null
at java.base/java.util.concurrent.locks.ReentrantReadWriteLock$Sync.tryReleaseShared(ReentrantReadWriteLock.java:427) ~[na:na]
at java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer.releaseShared(AbstractQueuedSynchronizer.java:1382) ~[na:na]
at java.base/java.util.concurrent.locks.ReentrantReadWriteLock$ReadLock.unlock(ReentrantReadWriteLock.java:897) ~[na:na]
at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:244) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:206) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:90) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
at org.springframework.data.mapping.context.MappingContext.getRequiredPersistentEntity(MappingContext.java:73) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:694) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeProperties(MappingMongoConverter.java:620) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:596) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:700) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeProperties(MappingMongoConverter.java:620) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:596) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:700) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeProperties(MappingMongoConverter.java:620) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:596) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:700) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeProperties(MappingMongoConverter.java:620) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:596) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:700) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeProperties(MappingMongoConverter.java:620) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:596) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:700) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeProperties(MappingMongoConverter.java:620) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:596) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:700) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeProperties(MappingMongoConverter.java:620) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:596) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
monoDB 似乎在持久化对象方面存在问题。
通过使用 synchronizedCollection 存储创建自定义存储库来解决此问题。现在不使用 mongoDB 或任何其他数据库。
@Repository
public class FutureTaskRepository {
// collection of futureTasks
private Collection<FutureTask> futureTasks = Collections.synchronizedCollection(new ArrayList<FutureTask>());
public Collection<FutureTask> findAll() {
return this.futureTasks;
}
public FutureTask find(FutureTask futureTask) {
Optional<FutureTask> optional = this.futureTasks.stream().filter(task -> task.equals(futureTask)).findFirst();
return optional.orElse(null);
}
public FutureTask findByConfiguration(Configuration configuration) {
Optional<FutureTask> optional = this.futureTasks.stream().filter(task -> task.getConfiguration()
.equals(configuration)).findFirst();
return optional.orElse(null);
}
public void insert(FutureTask futureTask) {
this.futureTasks.add(futureTask);
}
public void deleteAll() {
this.futureTasks.clear();
}
public void delete(FutureTask futureTask) {
FutureTask task = this.find(futureTask);
this.futureTasks.remove(task);
}
public boolean exists(FutureTask futureTask) {
return this.futureTasks.contains(futureTask);
}
public boolean existsByConfiguration(Configuration configuration) {
FutureTask futureTask = this.findByConfiguration(configuration);
return this.exists(futureTask);
}
}
我正在尝试使用 mongo 存储库将 save/insert 包装器键值 Class 放入我的 mongo 数据库中。
我要保存的模型是:
@Data
@AllArgsConstructor
@Document(collection = "futureTask")
public class FutureTask {
@Id
private Configuration configuration;
private ScheduledFuture<?> future;
}
存储库实现如下:
public interface FutureTaskRepository extends MongoRepository<FutureTask, Configuration> {
FutureTask findByConfiguration(Configuration configuration);
boolean existsByConfiguration(Configuration configuration);
}
FutureTaskRepository的调用如下:
ScheduledFuture<?> future = this.schedule(new RunnableTask(configuration), new CronTrigger(configuration.getCron()));
FutureTask futureTask = new FutureTask(configuration, future);
futureTaskRepository.insert(futureTask);
我收到以下错误:
java.lang.WhosebugError: null
at java.base/java.util.concurrent.locks.ReentrantReadWriteLock$Sync.tryReleaseShared(ReentrantReadWriteLock.java:427) ~[na:na]
at java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer.releaseShared(AbstractQueuedSynchronizer.java:1382) ~[na:na]
at java.base/java.util.concurrent.locks.ReentrantReadWriteLock$ReadLock.unlock(ReentrantReadWriteLock.java:897) ~[na:na]
at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:244) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:206) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:90) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
at org.springframework.data.mapping.context.MappingContext.getRequiredPersistentEntity(MappingContext.java:73) ~[spring-data-commons-2.3.5.RELEASE.jar:2.3.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:694) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeProperties(MappingMongoConverter.java:620) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:596) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:700) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeProperties(MappingMongoConverter.java:620) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:596) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:700) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeProperties(MappingMongoConverter.java:620) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:596) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:700) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeProperties(MappingMongoConverter.java:620) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:596) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:700) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeProperties(MappingMongoConverter.java:620) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:596) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:700) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeProperties(MappingMongoConverter.java:620) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:596) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:700) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeProperties(MappingMongoConverter.java:620) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:596) ~[spring-data-mongodb-3.0.5.RELEASE.jar:3.0.5.RELEASE]
monoDB 似乎在持久化对象方面存在问题。 通过使用 synchronizedCollection 存储创建自定义存储库来解决此问题。现在不使用 mongoDB 或任何其他数据库。
@Repository
public class FutureTaskRepository {
// collection of futureTasks
private Collection<FutureTask> futureTasks = Collections.synchronizedCollection(new ArrayList<FutureTask>());
public Collection<FutureTask> findAll() {
return this.futureTasks;
}
public FutureTask find(FutureTask futureTask) {
Optional<FutureTask> optional = this.futureTasks.stream().filter(task -> task.equals(futureTask)).findFirst();
return optional.orElse(null);
}
public FutureTask findByConfiguration(Configuration configuration) {
Optional<FutureTask> optional = this.futureTasks.stream().filter(task -> task.getConfiguration()
.equals(configuration)).findFirst();
return optional.orElse(null);
}
public void insert(FutureTask futureTask) {
this.futureTasks.add(futureTask);
}
public void deleteAll() {
this.futureTasks.clear();
}
public void delete(FutureTask futureTask) {
FutureTask task = this.find(futureTask);
this.futureTasks.remove(task);
}
public boolean exists(FutureTask futureTask) {
return this.futureTasks.contains(futureTask);
}
public boolean existsByConfiguration(Configuration configuration) {
FutureTask futureTask = this.findByConfiguration(configuration);
return this.exists(futureTask);
}
}