quarkusio/quarkus · error · HibernateException

Failed to generate Enhanced Proxy: default constructor is mi

Error message

Failed to generate Enhanced Proxy: default constructor is missing for entity '<entityName>'. Please add a default constructor explicitly.

What it means

Quarkus builds lazy-loading proxies for Hibernate entities ahead of time (no runtime bytecode generation in native). ProxyDefinitions.createFromMetadata tries to fetch the proxy constructor, which requires the entity class to have an accessible no-arg constructor; when the entity only has parameterized constructors, getting the constructor throws NoSuchMethodException, rethrown as this HibernateException.

Source

Thrown at extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/proxies/ProxyDefinitions.java:59

        this.proxyDefinitionMap = proxyDefinitionMap;
    }

    public static ProxyDefinitions createFromMetadata(Metadata storeableMetadata, PreGeneratedProxies preGeneratedProxies) {
        if (needAnyProxyDefinitions(storeableMetadata)) {
            final HashMap<Class<?>, ProxyClassDetailsHolder> proxyDefinitionMap = new HashMap<>();
            for (PersistentClass persistentClass : storeableMetadata.getEntityBindings()) {
                if (needsProxyGeneration(persistentClass)) {
                    final Class<?> mappedClass = persistentClass.getMappedClass();
                    final Class<?> proxyClassDefinition = getProxyClass(persistentClass, preGeneratedProxies);
                    if (proxyClassDefinition == null) {
                        continue;
                    }
                    final boolean overridesEquals = ReflectHelper.overridesEquals(mappedClass);
                    try {
                        proxyDefinitionMap.put(mappedClass,
                                new ProxyClassDetailsHolder(overridesEquals, proxyClassDefinition.getConstructor()));
                    } catch (NoSuchMethodException e) {
                        throw new HibernateException(
                                "Failed to generate Enhanced Proxy: default constructor is missing for entity '"
                                        + mappedClass.getName() + "'. Please add a default constructor explicitly.");
                    }
                }
            }
            return new ProxyDefinitions(proxyDefinitionMap);
        } else {
            return new ProxyDefinitions(Collections.emptyMap());
        }
    }

    private static boolean needAnyProxyDefinitions(Metadata storeableMetadata) {
        for (PersistentClass persistentClass : storeableMetadata.getEntityBindings()) {
            if (needsProxyGeneration(persistentClass))
                return true;
        }
        return false;
    }

View on GitHub (pinned to e1c734241f)

Solutions

  1. Add a public (or protected) no-argument constructor to the entity named in the message.
  2. If using Lombok, annotate the entity with @NoArgsConstructor and keep @AllArgsConstructor/@Builder if needed.
  3. Check every lazy association target of that entity — the entity name in the message is the one missing the constructor.

Example fix

// before
@Entity
public class Book {
    private String title;
    public Book(String title) { this.title = title; }
}

// after
@Entity
public class Book {
    protected Book() {} // for Hibernate proxying
    public Book(String title) { this.title = title; }
}
Defensive patterns

Strategy: validation

Validate before calling

// Check every @Entity has a no-arg constructor before startup
for (Class<?> e : entityClasses) {
    boolean hasNoArgCtor = Arrays.stream(e.getDeclaredConstructors())
        .anyMatch(c -> c.getParameterCount() == 0
            && (Modifier.isPublic(c.getModifiers()) || Modifier.isProtected(c.getModifiers())));
    if (!hasNoArgCtor) throw new IllegalStateException("Entity missing no-arg ctor: " + e.getName());
}

Prevention

When it happens

Trigger: An @Entity class (used as a lazy-association target or with lazy loading) declares only constructors with parameters and no explicit no-arg constructor; during SessionFactory creation Quarkus runs proxyDefinitions creation from the Hibernate metamodel and fails at getConstructor().

Common situations: Modern entity design with @Id and convenience constructors plus a parametrized constructor, forgetting JPA's requirement of a public/protected no-arg constructor; Lombok @Builder/@AllArgsConstructor without @NoArgsConstructor; entities introduced from other frameworks' codebases.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/2c93abe4c1fb354d. Report an issue: GitHub.