quarkiverse / quarkus-primefaces

Quarkus PrimeFaces Faces (JSF) Extension
https://github.com/primefaces/primefaces
Apache License 2.0
31 stars 3 forks source link

JPALazyDataModel not working for entity that extends PanacheEntity #215

Closed omasseau closed 2 days ago

omasseau commented 1 week ago

Hello,

It seems the JPALazyDataModel is not working for an entity that extends PanacheEntity. The id attribute (which is declared in the PanacheEntity class) cannot be found .

image

Entity :

@Entity(name = "storage_file")
public class StorageFile extends PanacheEntity {
   public String status;
   ...
}

View code :

@Named
@ViewScoped
@Data
public class StorageFilesModelView implements Serializable {
    @Inject
    EntityManager entityManager;

    JPALazyDataModel<StorageFile> model;

    @PostConstruct
    public void init() {
        model = JPALazyDataModel.<StorageFile>builder()
                .entityManager(() -> entityManager)
                .entityClass(StorageFile.class)
                .build();
    }
}

xhtml :

<!DOCTYPE html>
<html xmlns:h="jakarta.faces.html" xmlns:p="http://primefaces.org/ui">
<h:body>
    <h1>Storage files</h1>
    <h:form>
        <p:dataTable value="#{storageFilesModelView.model}" rows="10" var="storageFile">
            <p:column field="status"/>
        </p:dataTable>
    </h:form>
</h:body>
</html>

When trying to display the xhtml file I get this error :

2024-06-23 17:39:21,796 INFO  [io.quarkus] (Quarkus Main Thread) bd-file-storage 1.0.0-SNAPSHOT on JVM (powered by Quarkus 3.11.0) started in 11.054s. Listening on: http://localhost:8080
2024-06-23 17:39:21,796 INFO  [io.quarkus] (Quarkus Main Thread) Profile dev activated. Live Coding activated.
2024-06-23 17:39:21,796 INFO  [io.quarkus] (Quarkus Main Thread) Installed features: [agroal, awt, cdi, hibernate-orm, hibernate-orm-panache, hibernate-validator, itext, jdbc-postgresql, mailer, mailpit, myfaces, narayana-jta, poi, primefaces, primefaces-extensions, qute, rest, rest-jackson, rest-jsonb, scheduler, servlet, smallrye-context-propagation, smallrye-openapi, swagger-ui, vertx, websockets, websockets-client]
2024-06-23 17:39:28,112 INFO  [org.apa.myf.uti.ExternalSpecifications] (executor-thread-1) MyFaces Core Servlet 6.0 support enabled
2024-06-23 17:39:28,145 INFO  [org.apa.myf.el.ELResolverBuilder] (executor-thread-1) Chain of EL resolvers: [org.apache.myfaces.el.resolver.implicitobject.ImplicitObjectResolver@48f11f93, org.apache.myfaces.core.extensions.quarkus.runtime.spi.QuarkusCdiELResolver@13febdc0, org.apache.myfaces.el.resolver.CompositeComponentELResolver@5699330b, org.apache.myfaces.el.resolver.EmptyStringToNullELResolver@2169c500, org.apache.myfaces.el.resolver.FlashELResolver@61a45b39, org.apache.myfaces.el.resolver.ResourceResolver@752fa70, jakarta.el.ResourceBundleELResolver@18cc80fa, org.apache.myfaces.el.resolver.ResourceBundleResolver@77620726, org.apache.myfaces.el.resolver.ImportConstantsELResolver@345cf760, org.apache.el.stream.StreamELResolverImpl@24cd1ae1, jakarta.el.StaticFieldELResolver@587a95d2, jakarta.el.MapELResolver@3fc6e2cc, jakarta.el.ListELResolver@6c72f5a3, jakarta.el.ArrayELResolver@20a4f0de, jakarta.el.BeanELResolver@2c7c351d]
2024-06-23 17:39:28,163 INFO  [io.und.servlet] (executor-thread-1) No state saving method defined, assuming default server state saving
org.apache.myfaces.view.facelets.el.ContextAwareELException: jakarta.el.ELException: java.lang.IllegalArgumentException: The id attribute is not declared on this type [com.inetum.bd.file.storage.file.entity.StorageFile]
    at org.apache.myfaces.view.facelets.el.ContextAwareTagValueExpression.getValue(ContextAwareTagValueExpression.java:108)
    at jakarta.faces.component._DeltaStateHelper.eval(_DeltaStateHelper.java:339)
    at jakarta.faces.component.UIData.getValue(UIData.java:2020)
    at jakarta.faces.component.UIData.createDataModel(UIData.java:1936)
    at jakarta.faces.component.UIData.getDataModel(UIData.java:1899)
    at org.primefaces.component.api.UIData.setRowModel(UIData.java:420)
    at org.primefaces.component.api.UIData.setRowIndexWithoutRowStatePreserved(UIData.java:413)
    at org.primefaces.component.api.UIData.setRowIndex(UIData.java:473)
    at jakarta.faces.component.UIData.encodeEnd(UIData.java:1639)
    at jakarta.faces.component.UIComponentBase.encodeAll(UIComponentBase.java:523)
    at jakarta.faces.component.UIComponentBase.encodeAll(UIComponentBase.java:519)
    at jakarta.faces.component.UIComponentBase.encodeAll(UIComponentBase.java:519)
    at jakarta.faces.component.UIComponentBase.encodeAll(UIComponentBase.java:519)
    at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.renderView(FaceletViewDeclarationLanguage.java:1783)
    at org.apache.myfaces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:316)
    at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:122)
    at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:241)
    at jakarta.faces.webapp.FacesServlet.service(FacesServlet.java:225)
    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:63)
    at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
    at io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:67)
    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:133)
    at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
    at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:65)
    at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
    at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
    at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
    at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:247)
    at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:111)
    at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:108)
    at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
    at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
    at io.quarkus.undertow.runtime.UndertowDeploymentRecorder$9$1.call(UndertowDeploymentRecorder.java:630)
    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227)
    at io.undertow.servlet.handlers.ServletInitialHandler.handleRequest(ServletInitialHandler.java:152)
    at io.undertow.server.handlers.CanonicalPathHandler.handleRequest(CanonicalPathHandler.java:49)
    at io.quarkus.undertow.runtime.UndertowDeploymentRecorder$1.handleRequest(UndertowDeploymentRecorder.java:126)
    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:284)
    at io.undertow.server.DefaultExchangeHandler.handle(DefaultExchangeHandler.java:18)
    at io.quarkus.undertow.runtime.UndertowDeploymentRecorder$5$2.run(UndertowDeploymentRecorder.java:445)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
    at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:599)
    at org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2516)
    at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2495)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1521)
    at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:11)
    at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:11)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: jakarta.el.ELException: java.lang.IllegalArgumentException: The id attribute is not declared on this type [com.inetum.bd.file.storage.file.entity.StorageFile]
    at jakarta.el.BeanELResolver.getValue(BeanELResolver.java:351)
    at jakarta.el.CompositeELResolver.getValue(CompositeELResolver.java:136)
    at org.apache.el.parser.AstValue.getValue(AstValue.java:169)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:190)
    at org.apache.myfaces.view.facelets.el.ContextAwareTagValueExpression.getValue(ContextAwareTagValueExpression.java:100)
    ... 56 more
Caused by: java.lang.IllegalArgumentException: The id attribute is not declared on this type [com.inetum.bd.file.storage.file.entity.StorageFile]
    at org.hibernate.metamodel.model.domain.AbstractIdentifiableType.getDeclaredId(AbstractIdentifiableType.java:169)
    at org.hibernate.metamodel.model.domain.AbstractIdentifiableType.getDeclaredId(AbstractIdentifiableType.java:46)
    at org.primefaces.model.JPALazyDataModel$Builder.build(JPALazyDataModel.java:457)
    at com.inetum.bd.file.storage.file.front.primefaces.StorageFilesModelView.init(StorageFilesModelView.java:30)
    at com.inetum.bd.file.storage.file.front.primefaces.StorageFilesModelView_Bean.doCreate(Unknown Source)
    at com.inetum.bd.file.storage.file.front.primefaces.StorageFilesModelView_Bean.create(Unknown Source)
    at com.inetum.bd.file.storage.file.front.primefaces.StorageFilesModelView_Bean.create(Unknown Source)
    at org.apache.myfaces.cdi.util.ContextualStorage.createContextualInstance(ContextualStorage.java:154)
    at org.apache.myfaces.cdi.view.ViewScopeContext.get(ViewScopeContext.java:177)
    at org.apache.myfaces.core.extensions.quarkus.runtime.scopes.QuarkusViewScopeContext.get(QuarkusViewScopeContext.java:70)
    at io.quarkus.arc.InjectableContext.getIfActive(InjectableContext.java:60)
    at io.quarkus.arc.impl.ClientProxies.getSingleContextDelegate(ClientProxies.java:28)
    at com.inetum.bd.file.storage.file.front.primefaces.StorageFilesModelView_ClientProxy.arc$delegate(Unknown Source)
    at com.inetum.bd.file.storage.file.front.primefaces.StorageFilesModelView_ClientProxy.getModel(Unknown Source)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at jakarta.el.BeanELResolver.getValue(BeanELResolver.java:346)
    ... 60 more

Quarkus version : 3.11.0 Primefaces extension version : 3.14.1

melloware commented 1 week ago

I will take a look. I know it works with normal JPA but PF core doesn't test with Panache as it's a quarkus only library.

tandraschko commented 1 week ago

You can also manually define the field, converter or getter for the id. Check PF docs as workaround

tandraschko commented 1 week ago

Also its propably a panache bug, i would say it must work

melloware commented 1 week ago

This does feel like a Panache bug. Let me investigate.

tandraschko commented 1 week ago

PanacheEntity has a id So either panache or hibernate bug

melloware commented 1 week ago

@omasseau i opened a Quarkus ticket with reproducer: https://github.com/quarkusio/quarkus/issues/41389

melloware commented 1 week ago

@tandraschko looks like a PF issue. Here is what the Panache guy says

I checked it out, and it appears the javadoc of getDeclaredId is wrong, because it follows the same principles as Java's reflection, where declared means there will be no super-type lookup: it will be limited to the entity type passed as parameter, and not look for its mapped superclasses. You should use getId to lookup IDs that can be defined in supertypes. I just checked it and that works.

melloware commented 1 week ago

PrimeFaces PR submitted: https://github.com/primefaces/primefaces/pull/12179

melloware commented 2 days ago

3.14.2 is in Maven Central which fixes this issue.