Hey, tapestry-jpa supports latest Hibernate 5.x, at least we have it running in production with 5.2.5.Final You don't have to provide hibernate.cfg.xml, although the settings you have in your persistence.xml are not correct for 5.2.x Hibernate
Here's a working persistence.xml that we use in our apps: <?xml version="1.0" encoding="UTF-8" ?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd" version="1.0"> <persistence-unit name="my-pu" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> <exclude-unlisted-classes>true</exclude-unlisted-classes> <mapping-file>META-INF/orm.xml</mapping-file> <properties> <property name="hibernate.hikari.dataSource.url" value="jdbc:postgresql://localhost/dbname"/> <property name="hibernate.hikari.dataSource.user" value="username"/> <property name="hibernate.hikari.dataSource.password" value="password"/> <property name="hibernate.hbm2ddl.auto" value="validate"/> <property name="hibernate.show_sql" value="false" /> <property name="hibernate.connection.provider_class" value="org.hibernate.hikaricp.internal.HikariCPConnectionProvider"/> <property name="hibernate.auth" value="Container" /> <property name="hibernate.hikari.connectionTimeout" value="300000" /> <property name="hibernate.hikari.maximumPoolSize" value="50" /> <property name="hibernate.hikari.minimumIdle" value="5" /> <property name="hibernate.hikari.dataSourceClassName" value="org.postgresql.ds.PGSimpleDataSource" /> </properties> </persistence-unit> </persistence> Above configuration uses HikariCP for connection pooling. Some relevant dependencies: compile ("org.hibernate:hibernate-core:5.2.5.Final") { exclude group: 'commons-collections' } compile ("org.hibernate:hibernate-hikaricp:5.2.5.Final") { exclude group: "com.zaxxer", module: "HikariCP-java6" } compile 'com.zaxxer:HikariCP:2.5.1' compile "org.postgresql:postgresql:9.4.1212" The file META-INF/orm.xml has no declarations, not sure if it's still necessary, but some earlier versions of Hibernate complained without it: <?xml version="1.0" encoding="UTF-8"?> <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd" version="2.0"> </entity-mappings> Hope this helps. On Wed, Jan 18, 2017 at 2:19 PM, Jochimsen, Janko < janko.jochim...@urios-beratung.de> wrote: > > Hi, > > I am trying to switch my application from a standard tapestry-hibernate > version to a tapestry-jpa version. I would like to have a pure hibernate > solution and skip any eclipselink dependency. > > After spending some time with > http://tapestry.apache.org/integrating-with-jpa.html > I am more or less lost as the documentation is not working and the > comments and remarks from basileChandesris are not really clear. > > After I discovered that it seems to be necessary to provide this line: > <provider>org.hibernate.ejb.HibernatePersistence</provider> > my persistence.xml itself looks like this: > > <?xml version="1.0" encoding="UTF-8"?> > <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0"> > <persistence-unit name="DemoUnit" transaction-type="RESOURCE_LOCAL"> > <provider>org.hibernate.ejb.HibernatePersistence</provider> > <properties> > <property name="hibernate.connection.driver_class">org.postgresql. > Driver</property> > <property name="hibernate.connection.url">jdbc:postgresql:// > localhost:5432/xxx-test</property> > <property name="hibernate.connection.username">XX</property> > <property name="hibernate.connection.password">XXX</property> > <property name="hibernate.dialect">org.hibernate.dialect. > PostgreSQLDialect</property> > <property name="hibernate.hbm2ddl.auto" value="create-drop"/> > </properties> > </persistence-unit> > </persistence> > > As it is not stated in the guide I do not provide a hibernate.cfg.xml file. > > > The relevant part of the POM file reads: > <dependency> > > <groupId>org.apache.tapestry</groupId> > <artifactId>tapestry-jpa</ > artifactId> > <version>${tapestry-release- > version}</version> > </dependency> > > <dependency> > <groupId>org.hibernate</ > groupId> > <artifactId>hibernate- > entitymanager</artifactId> > > <version>${hibernate-version}</version> > <exclusions> > <exclusion> > > <!-- omit Geronimo JPA spec to avoid conflict with Hibernate JPA spec > --> > > <groupId>org.apache.geronimo.specs</groupId> > > <artifactId>geronimo-jpa_2.0_spec</artifactId> > </exclusion> > </exclusions> > </dependency> > > > With > <properties> > <tapestry-release-version>5.4. > 1</tapestry-release-version> > <hibernate-version>4.2.6. > Final</hibernate-version> > .... > > </properties> > > I use 4.2.6.Finale of hibernate as 4.3.1.Final (what is stated as the > correct version for Tapestry 5.4. in > http://tapestry.apache.org/release-notes-54.html > gives me an error. > > > AppModule.java contains: > > @Match("*Dao") > public static void adviseTransactionally( > JpaTransactionAdvisor advisor, > MethodAdviceReceiver receiver) { > > advisor.addTransactionCommitAdvice(receiver); > } > > > Although it is not mentioned in > > http://tapestry.apache.org/integrating-with-jpa.html > > I also added the following statement in the AppModule.java : > > @Contribute(EntityManagerSource.class) > public static void configurePersistenceUnitInfos( > MappedConfiguration<String,PersistenceUnitConfigurer> cfg) { > > PersistenceUnitConfigurer configurer = new > PersistenceUnitConfigurer() { > public void configure(TapestryPersistenceUnitInfo > unitInfo) { > unitInfo.addManagedClass(User.class); > } > }; > cfg.add("DemoUnit", configurer); > } > > This crashes the App on start up with the following Error Massage: > org.apache.tapestry5.ioc.internal.OperationException: > javax.persistence.PersistenceException: > [PersistenceUnit: DemoUnit] Unable to build EntityManagerFactory > > Deep down in the Exception Stack there > Caused by: org.hibernate.HibernateException: Connection cannot be null > when 'hibernate.dialect' not set > > This is all not really helpful at least to me. > > > If I omit the statement configurePersistenceUnitInfos ... > > The App starts. But as soon as it calls the entityManager in the following > class via add(User user); > public class UserDAOImpl implements UserDAO > { > @PersistenceContext(unitName = "DemoUnit") > private EntityManager entityManager; > > @Override > @PersistenceContext(unitName = "DemoUnit") > public void add(final User user) > { > entityManager.persist(user); > } > > @Override > @SuppressWarnings( > { "unchecked" }) > public List<User> findAll() > { > return entityManager.createQuery("select u from User u order by > u.id desc").getResultList(); > } > > @Override > public void delete(final User... users) > { > for (final User user : users) > entityManager.remove(user); > } > > @Override > public void deleteAll() > { > for (final User u : findAll()) > { > entityManager.remove(u); > } > } > } > > I get the error message: > > Unable to locate a single EntityManager. You must provide ... > > > From the comments and other posts it is clear that the documentation is > outdated and not really working. But there seems to be no really helpful > alternative. I would be very grateful if someone could give me a hint where > to look or explain to me what is going on here. > > > Cheers > > Janko > > > > > > > > -- Dmitry Gusev AnjLab Team http://anjlab.com