最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - Error initializing database using Quarkus - Stack Overflow

programmeradmin2浏览0评论

Here's the error stack trace:

Caused by: java.lang.IllegalStateException: No current Vertx context found
    at io.quarkus.hibernate.reactive.panachemon.runtime.SessionOperations.vertxContext(SessionOperations.java:191)
    at io.quarkus.hibernate.reactive.panachemon.runtime.SessionOperations.getSession(SessionOperations.java:141)
    at io.quarkus.hibernate.reactive.panachemon.runtime.AbstractJpaOperations.getSession(AbstractJpaOperations.java:368)
    at io.quarkus.hibernate.reactive.panachemon.runtime.AbstractJpaOperations.count(AbstractJpaOperations.java:215)

The UserGroup class extends PanacheEntityBase, and that's when this issue occurred. I'm not sure how to resolve it. Can anyone offer some advice or solutions?

@ApplicationScoped
public class LifecycleBean {

    @Startup
    public Uni<Void> initialize() {
        return initDefaultUserGroup();
    }


    private Uni<Void> initDefaultUserGroup() {
        Log.info("------------- init DefaultUserGroup -------------");
        Uni<Long> count = UserGroup.count("select count(id) from UserGroup where userGroupType = 'ADMIN'");
        count.onItem().transformToUni(e->{
            if (e == 0) {
                UserGroup userGroup = new UserGroup();
                userGroup.userGroupType = UserGroup.UserGroupType.ADMIN;
                return UserGroup.persist(userGroup).replaceWithVoid();
            } else if (e > 1) {
                throw new RuntimeException("admin group count is greater than 1 !");
            }
            return null;
        }).subscribe();
        return null;
    }

}

I tried a few things but couldn't work it out, I had never used reactive before

发布评论

评论列表(0)

  1. 暂无评论