setFirstResult, and setMaxResults don't work for EJB Queries in Wildfly 32.0.0

110 views
Skip to first unread message

Arkady Zelekman

unread,
Aug 29, 2024, 5:45:05 AM8/29/24
to WildFly
Hi, team

I have very simple following code:

Query query = entityManager.createNamedQuery(queryName);
query.setFirstResult(offset);
query.setMaxResults(limit);

Collection result = query.getResultList();

It returns all records according to query, doesn't consider to values I put for "offset" and "limit".

I use sybase database, my persistence.xml looks following:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
   xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
        http://xmlns.jcp.org/xml/ns/persistence
        http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="nms">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>java:/AllotDS</jta-data-source>
...
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.SybaseDialect" />
</properties>
</persistence-unit>
</persistence>

Thanks for help in advance.

Staffan Horke

unread,
Aug 29, 2024, 7:20:47 AM8/29/24
to WildFly
Hi Arkady,

Since Hibernate 6 it is no longer necessary to specify database dialects. Using the setting hibernate.dialect is discouraged since It is considered that Hibernate now does a good job on its own to figure out what dialect implementation to use.

I don't know Sybase, but I can see that Hibernate has two different dialect implementations for Sybase.
Maybe you can start by trying to leave the dialect setting out and see if it works better for you?

Best Regards,
Staffan Hörke




--
You received this message because you are subscribed to the Google Groups "WildFly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wildfly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/wildfly/c51b7a1f-dc43-4b2e-b59e-6dc40bec6502n%40googlegroups.com.

Arkady Zelekman

unread,
Aug 29, 2024, 8:40:12 AM8/29/24
to WildFly
If I am not putting the value for dialect, the server fails to start. It fails with following error:

"{\"WFLYCTL0080: Failed services\" => {\"jboss.persistenceunit.\\\"NMS.ear#nms\\\".__FIRST_PHASE__\" => \"org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] due to: Unable to determine Dialect without JDBC metadata (please set 'jakarta.persistence.jdbc.url' for common cases or 'hibernate.dialect' when a custom Dialect implementation must be provided)
    Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] due to: Unable to determine Dialect without JDBC metadata (please set 'jakarta.persistence.jdbc.url' for common cases or 'hibernate.dialect' when a custom Dialect implementation must be provided)
    Caused by: org.hibernate.HibernateException: Unable to determine Dialect without JDBC metadata (please set 'jakarta.persistence.jdbc.url' for common cases or 'hibernate.dialect' when a custom Dialect implementation must be provided)\"}}"

Problem solved after I put dialect to be org.hibernate.dialect.SybaseASEDialect.

Thank you very much for help.

Staffan Horke

unread,
Aug 29, 2024, 3:08:20 PM8/29/24
to WildFly
Hi,

I'm glad it worked out for you with a more specific database dialect.

About the error you see, if the database is not accessible during startup the right thing is still to tell hibernate which database you are using.

Up to the current latest released version, 33.0.1.Final, using hibernate.dialect is the way to go.

When wildfly moves to hibernate 6.5 and beyond, the recommended approach is to use the Jakarta Persistence properties instead. Here is an example:

# disable use of JDBC database metadata
hibernate.boot.allow_jdbc_metadata_access=false

# explicitly specify database and version
jakarta.persistence.database-product-name=MariaDB
jakarta.persistence.database-major-version=10
jakarta.persistence.database-minor-version=4


Best Regards,
Staffan Hörke

Reply all
Reply to author
Forward
0 new messages