admin管理员组

文章数量:1344965

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

本文标签: javaError initializing database using QuarkusStack Overflow