Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No Persistence provider for EntityManager named #291

Closed
sysmat opened this issue Feb 7, 2023 · 13 comments
Closed

No Persistence provider for EntityManager named #291

sysmat opened this issue Feb 7, 2023 · 13 comments
Assignees

Comments

@sysmat
Copy link

sysmat commented Feb 7, 2023

  • java 19
  • dependencies
<dependency>
            <groupId>jakarta.validation</groupId>
            <artifactId>jakarta.validation-api</artifactId>
            <version>3.0.2</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core-jakarta</artifactId>
            <version>5.6.15.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.orm</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>6.2.0.CR2</version>
        </dependency>
        <dependency>
            <groupId>com.speedment.jpastreamer</groupId>
            <artifactId>jpastreamer-core</artifactId>
            <version>1.1.2</version>
        </dependency>

        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <version>8.0.32</version>
        </dependency>
  • src/main/resources/META-INF/persistence
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.2"
             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_2.xsd">
    
  <persistence-unit name="vid_reservation" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <class>si.jpastreamer.AaiUser</class>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/vid_reservation?zeroDateTimeBehavior=CONVERT_TO_NULL"/>
      <property name="javax.persistence.jdbc.user" value="*****"/>
      <property name="javax.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver"/>
      <property name="javax.persistence.jdbc.password" value="******"/>
      <property name="javax.persistence.schema-generation.database.action" value="none"/>
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
      <property name="org.hibernate.orm.jdbc.bind" value="trace"/>
    </properties>
  </persistence-unit>
</persistence>
  • error:
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named vid_reservation
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
	at com.speedment.jpastreamer.application.standard.internal.StandardJPAStreamerBuilder.<init>(StandardJPAStreamerBuilder.java:38)
	at com.speedment.jpastreamer.application.standard.StandardJPAStreamerBuilderFactory.create(StandardJPAStreamerBuilderFactory.java:30)
	at com.speedment.jpastreamer.application.JPAStreamer.createJPAStreamerBuilder(JPAStreamer.java:230)
	at com.speedment.jpastreamer.application.JPAStreamer.of(JPAStreamer.java:286)
	at si.jpastreamer.JpaStreamer.main(JpaStreamer.java:35)
  • but when using direct createEntityManagerFactory it works fine, bit not with JPAStreamer
  • code:
package si.jpastreamer;

import com.speedment.jpastreamer.application.JPAStreamer;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;

public class JpaStreamer {

   private static final String PERSISTENCE_UNIT_NAME = "vid_reservation";
   private static EntityManagerFactory factory;


    public static void main(String[] args) {

        factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
        var em = factory.createEntityManager();
        // works fine
        var q = em.createQuery("select u from AaiUser u");
        var users = q.getResultList();
        users.forEach(u -> {
            System.out.println("user="+u);
        });


       // not working 
       JPAStreamer jpaStreamer = JPAStreamer.of(PERSISTENCE_UNIT_NAME);
       jpaStreamer.stream(AaiUser.class)
                  .forEach(System.out::println);

    }
}
@julgus
Copy link
Member

julgus commented Feb 16, 2023

Thanks for submitting this issue, I'll be looking into it. What about if you pass the factory to JPAStreamer directly?

JPAStreamer.of(factory)

@sysmat
Copy link
Author

sysmat commented Feb 16, 2023

@julgus there is no such a method in JPAStreamer

@sysmat
Copy link
Author

sysmat commented Feb 16, 2023

  • argument mismatch; jakarta.persistence.EntityManagerFactory cannot be converted to javax.persistence.EntityManagerFactory

@sysmat
Copy link
Author

sysmat commented Feb 16, 2023

  • using jpastreamer-core:1.1.3
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

....

JPAStreamer jpaStreamer = JPAStreamer.of(factory);
  • still error:
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named vid_reservation
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
	at si.jpastreamer.JpaStreamer.main(JpaStreamer.java:21)

@julgus
Copy link
Member

julgus commented Feb 17, 2023

Oh, I see, the EntityManagerFactory is an instance of jakarta.persistence.EntityManagerFactory that is part of JPA 3. At this point, JPAStreamer does not support JPA 3 but will likely do so in the near future.

@julgus
Copy link
Member

julgus commented Feb 17, 2023

I have created a separate issue for JPA 3 support here: #299.

@sysmat
Copy link
Author

sysmat commented Feb 18, 2023

I'm using persistence version="2.2"

@sysmat
Copy link
Author

sysmat commented Feb 18, 2023

I think that you should have quick start with full dependency tree , or working example in github

@sysmat
Copy link
Author

sysmat commented Feb 18, 2023

  • pom
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>

<dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>javax.persistence-api</artifactId>
            <version>2.2</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.6.15.Final</version>
        </dependency>

        <dependency>
            <groupId>com.speedment.jpastreamer</groupId>
            <artifactId>jpastreamer-core</artifactId>
            <version>1.1.3</version>
        </dependency>

        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <version>8.0.32</version>
        </dependency>
  • java:
JPAStreamer jpaStreamer = JPAStreamer.of(PERSISTENCE_UNIT_NAME);
jpaStreamer.stream(AaiUser.class)
                  .forEach(System.out::println); 
  • error:
INFO: HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
   _________  ___      _                                      
  |_  | ___ \/ _ \    | |                                     
    | | |_/ / /_\ \___| |_ _ __ ___  __ _ _ __ ___   ___ _ __ 
    | |  __/|  _  / __| __| '__/ _ \/ _` | '_ ` _ \ / _ \ '__|
/\__/ / |   | | | \__ \ |_| | |  __/ (_| | | | | | |  __/ |   
\____/\_|   \_| |_/___/\__|_|  \___|\__,_|_| |_| |_|\___|_|
:: JPAstreamer Open Source :: 1.1.3
Copyright Speedment, Inc.
Licensed under LGPL 2.1
Running under Java(TM) SE Runtime Environment 1.8.0_112-b15
AaiUser{id=1, name=Mojster, surname=Za, [email protected], [email protected], created=2022-02-25 07:20:35.0, updated=2022-05-24 10:58:17.0, reservations=[Reservation{id=4, name=matematika na hitro, roomUUID=yuws-ftgh-kzgu, expire=2022-02-25 07:20:35.0, jitsiJwt=null, created=2022-02-25 07:20:35.0, updated=2022-02-25 07:20:35.0}, Reservation{id=5, name=vrane v mestih, roomUUID=r228-nfhq-ddkg, expire=2022-02-25 07:20:35.0, jitsiJwt=null, created=2022-02-25 07:20:35.0, updated=2022-02-25 07:20:35.0}, Reservation{id=11, name=sadsadsdsa, roomUUID=32am-r0fb-z9dx, expire=2022-04-14 22:00:00.0, jitsiJwt=null, created=2022-03-31 11:19:35.0, updated=2022-03-31 12:14:53.0}, Reservation{id=15, name=tomaž, roomUUID=hyg4-efmo-rloj, expire=2022-05-24 22:00:00.0, jitsiJwt=null, created=2022-05-24 09:42:28.0, updated=2022-05-24 09:42:28.0}]}
feb. 18, 2023 9:58:34 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 0, SQLState: S1000
feb. 18, 2023 9:58:34 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Operation not allowed after ResultSet closed
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not advance using next()
	at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
	at org.hibernate.internal.ScrollableResultsImpl.convert(ScrollableResultsImpl.java:71)
	at org.hibernate.internal.ScrollableResultsImpl.next(ScrollableResultsImpl.java:106)
	at org.hibernate.query.internal.ScrollableResultsIterator.hasNext(ScrollableResultsIterator.java:33)
	at java.util.Iterator.forEachRemaining(Iterator.java:115)
	at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
	at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
	at org.hibernate.query.spi.StreamDecorator.forEach(StreamDecorator.java:153)
	at com.speedment.jpastreamer.pipeline.standard.internal.terminal.InternalTerminalOperationFactory.lambda$createForEach$0(InternalTerminalOperationFactory.java:77)
	at com.speedment.jpastreamer.builder.standard.internal.BaseStreamBuilder.renderAndThenAccept(BaseStreamBuilder.java:165)
	at com.speedment.jpastreamer.builder.standard.internal.StreamBuilder.forEach(StreamBuilder.java:144)
	at com.speedment.jpastreamer.autoclose.standard.internal.AutoClosingStream.lambda$forEach$0(AutoClosingStream.java:139)
	at com.speedment.jpastreamer.autoclose.standard.internal.AbstractAutoClosingBaseStream.finallyClose(AbstractAutoClosingBaseStream.java:87)
	at com.speedment.jpastreamer.autoclose.standard.internal.AutoClosingStream.forEach(AutoClosingStream.java:139)
	at si.jpastreamer.JpaStreamer.main(JpaStreamer.java:38)
Caused by: java.sql.SQLException: Operation not allowed after ResultSet closed
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
	at com.mysql.cj.jdbc.result.ResultSetImpl.checkClosed(ResultSetImpl.java:485)
	at com.mysql.cj.jdbc.result.ResultSetImpl.next(ResultSetImpl.java:1802)
	at org.hibernate.internal.ScrollableResultsImpl.next(ScrollableResultsImpl.java:101)
	... 12 more

@julgus
Copy link
Member

julgus commented Mar 3, 2023

I think that you should have quick start with full dependency tree , or working example in github

Have you seen https://github.com/speedment/jpa-streamer-demo?

@julgus
Copy link
Member

julgus commented Mar 9, 2023

Sorry for taking so long to respond. I have been able to reproduce this issue and conclude that this is due to how Hibernate handles the fetching of the list of reservations associated with your AaiUser. The original ResultSet returned by the base query does not contain the reservations, only the AaiUsers with references into the Reservations table. When you are attempting to print the entity, Hibernate will issue a new query to fetch the associated reservations. Upon opening a new ResultSet, the first is closed. This explains why you are seeing just a single entity being printed, and then the exception.

One workaround is to limit the printed fields to fields that are available in the original ResultSet (field of AaiUser with no references to other tables) e.g.

JPAStreamer jpaStreamer = JPAStreamer.of(PERSISTENCE_UNIT_NAME);
jpaStreamer.stream(AaiUser.class)
                  .forEach(u -> System.out.println(u.name); 

If the reservations are important, make sure to join in the reservations in the stream query:

JPAStreamer jpaStreamer = JPAStreamer.of(PERSISTENCE_UNIT_NAME);
jpaStreamer.stream(StreamConfiguration.of(AaiUser.class).joining(AaiUser$.reservations))
                  .forEach(System.out::println); 

This ensures that Hibernate will fetch all the relevant information in a single ResultSet. We will be looking into how we can improve the user experience of JPAStreamer in cases like these.

@sysmat
Copy link
Author

sysmat commented Jun 27, 2023

  • error still exist on versions
<dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>6.2.5.Final</version>
        </dependency>
  <dependency>
            <groupId>com.speedment.jpastreamer</groupId>
            <artifactId>jpastreamer-core</artifactId>
            <version>3.0.2</version>
        </dependency>
 <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <version>8.0.33</version>
        </dependency>
  • error:
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not advance using next()
	at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
	at org.hibernate.internal.ScrollableResultsImpl.convert(ScrollableResultsImpl.java:71)
	at org.hibernate.internal.ScrollableResultsImpl.next(ScrollableResultsImpl.java:106)
	at org.hibernate.query.internal.ScrollableResultsIterator.hasNext(ScrollableResultsIterator.java:33)
	at java.base/java.util.Iterator.forEachRemaining(Iterator.java:132)
	at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1921)
	at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762)
	at org.hibernate.query.spi.StreamDecorator.forEach(StreamDecorator.java:153)
	at com.speedment.jpastreamer.pipeline.terminal.standard.internal.InternalTerminalOperationFactory.lambda$createForEach$0(InternalTerminalOperationFactory.java:77)
	at com.speedment.jpastreamer.builder.standard.internal.BaseStreamBuilder.renderAndThenAccept(BaseStreamBuilder.java:165)
	at com.speedment.jpastreamer.builder.standard.internal.StreamBuilder.forEach(StreamBuilder.java:144)
	at com.speedment.jpastreamer.autoclose.standard.internal.AutoClosingStream.lambda$forEach$0(AutoClosingStream.java:139)
	at com.speedment.jpastreamer.autoclose.standard.internal.AbstractAutoClosingBaseStream.finallyClose(AbstractAutoClosingBaseStream.java:87)
	at com.speedment.jpastreamer.autoclose.standard.internal.AutoClosingStream.forEach(AutoClosingStream.java:139)
	at si.jpastreamer.JpaStreamer.main(JpaStreamer.java:37)
Caused by: java.sql.SQLException: Operation not allowed after ResultSet closed
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:130)

@julgus julgus self-assigned this Jun 27, 2023
@julgus julgus added this to the 3.0.3 milestone Jun 27, 2023
@julgus julgus modified the milestones: 3.0.3, 3.0.4 Jul 10, 2023
@julgus
Copy link
Member

julgus commented Aug 29, 2023

Regrettably, as outlined in the description, this issue stems from Hibernate's behavior of closing the initial resultset when a second one is opened. To address this, I would recommend that you incorporate a join operation to consolidate information from other tables. This approach guarantees that all pertinent data is retrieved within a single resultset.

Given this context, I will proceed to close this issue, as I don't consider it to be a bug within JPAStreamer. If you have further questions or encounter related concerns, please don't hesitate to reopen the issue or reach out for additional assistance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

2 participants