Possible workaround could be to use tapestry-jpa, it should work fine with latest Hibernate (5.2.x).
It won't give you an instance of `Session` as a service, but you could either: - type-cast `EntityManager` to the `Session` (as Hibernate `Session` extends JPA's `EntityManager`), or - use get it with `em.unwrap(Session.class)` You could also implement an ObjectProvider that would do this for you, as tapestry-jpa is doing for EntityManagers [1]. [1] https://github.com/apache/tapestry-5/blob/95a548ec488a3c09c16117a0e6f9d3ce28db0322/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/EntityManagerObjectProvider.java On Tue, May 9, 2017 at 11:04 AM, Thomas Mayer <thomas.ma...@student.kit.edu> wrote: > Thanks for the hint. Indeed, that would be an option and it is great to > see that Tapestry already covers that use case for Hibernate, too. > > However, using tapestry-hibernate-core takes me back to hibernate-core > 4.3.6.Final which got released in July 2014 (although a 4.3.11.Final > also is available, dating back to August 2015). > > It's just that I'm using Hibernate 5.2.10.Final already. So far, I'm > quite happy with that. Basically, that's one of the reasons for me to go > for isolated framework components. > > I worked around my original issue. If someone fixes it, that would still > be great. Maybe that becomes obvious as soon as tapestry-hibernate-core > gets updated to a recent version of Hibernate. > > Best regards > Thomas > > Am 09.05.2017 um 09:13 schrieb Lance Java: > > There's tapestry-hibernate-core which only depends on tapestry-ioc. > > tapestry-hibernate builds on top of this with web specific services > > > > https://mvnrepository.com/artifact/org.apache.tapestry/ > tapestry-hibernate-core/5.4.3 > > > > On 9 May 2017 03:54, "Thomas Mayer" <thomas.ma...@student.kit.edu> > wrote: > > > >> Hello Thiago, > >> > >> thanks for your answer. > >> > >> The idea was to only use tapestry-ioc which is supposed to be usable as > >> an isolated component with no dependency to tapestry-core. > >> > >> tapestry-hibernate, however, depends on tapestry-core, according to > >> https://mvnrepository.com/artifact/org.apache.tapestry/ > >> tapestry-hibernate/5.4.3 > >> That's not necessarily a no-go for general usage, but "taints" my > >> original concept. > >> > >> For my use case it would be perfectly fine to only use one Hibernate > >> session throughout the project (no threading, etc.). The project itself > >> does some batch processing (no web context, etc.). > >> > >> Should I ever need multiple Sessions, that's where @ServiceId could step > >> in (still single threaded). > >> > >> Still, all of these considerations don't deal whith the original > >> question why creating this Session service is failing so hard. At least > >> good to know that my code should run in general. Thanks for that. > >> > >> Now, where is the missing part? Is it Tapestry-Ioc related or Hibernate > >> related? > >> > >> If the code should run, but fails, then, maybe there is a bug/limitation > >> somewhere which might be worth to get fixed. > >> > >> Best regards > >> Thomas > >> > >> Am 09.05.2017 um 00:57 schrieb Thiago H. de Paula Figueiredo: > >>> Hello! > >>> > >>> Why don't you just use tapestry-hibernate to let it deal with creating > >> and > >>> handling Hibernate sessions? > >>> https://tapestry.apache.org/using-tapestry-with-hibernate.html > >>> > >>> Also, I believe your code may not be incorrect, but it's not good. > Unless > >>> you want only one Hibernate session for the whole application and you > >> never > >>> have threads in parallel using it, your code will be fail hard. > Hibernate > >>> sessions are not thread-safe and Tapestry-IoC services are singletons > by > >>> default. Your code doesn't tell T-IoC the service is per-thread. > >>> > >>> Also, why are you using @ServiceId? Tapestry-IoC services are usually > >>> defined by their type, not by their id, and service ids are generally > >> only > >>> used when you have more than one service with the same type. > >>> > >>> > >>> On Mon, May 8, 2017 at 2:56 AM, Thomas Mayer < > >> thomas.ma...@student.kit.edu> > >>> wrote: > >>> > >>>> Hi, this report/question is for > >>>> > >>>> tapestry-ioc 5.4.3 > >>>> hibernate-core 5.2.10.Final > >>>> openjdk version "1.8.0_121" > >>>> OpenJDK Runtime Environment (build 1.8.0_121-8u121-b13-0ubuntu1. > >>>> 16.04.2-b13) > >>>> OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode) > >>>> > >>>> I'm trying to have a ServiceId for a hibernate Session: > >>>> > >>>> @ServiceId("HibernateSession") > >>>> public static Session buildHibernateSession( > >>>> ObjectLocator objectLocator > >>>> ) { > >>>> return new Configuration() > >>>> .configure("hibernate.cfg.xml") > >>>> .buildSessionFactory() > >>>> .openSession(); > >>>> } > >>>> > >>>> As soon as the HibernateSession is invoked by Tapestry-IOC, I get an > >>>> error: java.lang.ClassFormatError: Duplicate method name&signature in > >>>> class file $Session_350f95bde0b5 > >>>> > >>>> Please note thate I can serve the SessionFactory perfectly fine with > >>>> Tapestry-IoC (just by omitting the "openSession()"). > >>>> > >>>> Is there something wrong in the code above? > >>>> Can someone reproduce it? > >>>> Is this a bug in Tapestry-IoC? > >>>> Is this a bug/limitation in Hibernate? > >>>> > >>>> > >>>> > >>>> 2017-05-08 07:31:02 DEBUG HibernateSession:261 - Creating proxy for > >>>> service HibernateSession > >>>> Exception in thread "main" java.lang.ClassFormatError: Duplicate > method > >>>> name&signature in class file $Session_350f95bde0b5 > >>>> at java.lang.ClassLoader.defineClass1(Native Method) > >>>> at java.lang.ClassLoader.defineClass(ClassLoader.java:763) > >>>> at java.lang.ClassLoader.defineClass(ClassLoader.java:642) > >>>> at > >>>> org.apache.tapestry5.internal.plastic.PlasticClassLoader. > >>>> defineClassWithBytecode(PlasticClassLoader.java:52) > >>>> at > >>>> org.apache.tapestry5.internal.plastic.PlasticClassPool. > >>>> realize(PlasticClassPool.java:160) > >>>> at > >>>> org.apache.tapestry5.internal.plastic.PlasticClassPool. > >>>> realizeTransformedClass(PlasticClassPool.java:139) > >>>> at > >>>> org.apache.tapestry5.internal.plastic.PlasticClassImpl. > >> createInstantiator( > >>>> PlasticClassImpl.java:648) > >>>> at > >>>> org.apache.tapestry5.plastic.PlasticManager.createProxy( > >>>> PlasticManager.java:253) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.services.PlasticProxyFactoryImpl. > >>>> createProxy(PlasticProxyFactoryImpl.java:68) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.ModuleImpl.createProxyInstance( > >>>> ModuleImpl.java:484) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.ModuleImpl. > >> createProxy(ModuleImpl.java: > >>>> 478) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.ModuleImpl.access$ > >>>> 900(ModuleImpl.java:40) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.ModuleImpl$4.invoke( > >> ModuleImpl.java:322) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.OperationTrackerImpl. > >>>> invoke(OperationTrackerImpl.java:82) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke( > >>>> PerThreadOperationTracker.java:72) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.RegistryImpl.invoke( > >>>> RegistryImpl.java:1260) > >>>> at org.apache.tapestry5.ioc.internal.ModuleImpl.create( > >>>> ModuleImpl.java:344) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.ModuleImpl.access$ > >>>> 100(ModuleImpl.java:40) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.ModuleImpl$1.invoke( > >> ModuleImpl.java:198) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.util.ConcurrentBarrier.withWrite( > >>>> ConcurrentBarrier.java:139) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.ModuleImpl$2.invoke( > >> ModuleImpl.java:215) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.util.ConcurrentBarrier.withRead( > >>>> ConcurrentBarrier.java:83) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.ModuleImpl. > >> findOrCreate(ModuleImpl.java: > >>>> 221) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.ModuleImpl. > >> getService(ModuleImpl.java: > >>>> 112) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.RegistryImpl. > >>>> getService(RegistryImpl.java:497) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.ObjectLocatorImpl. > >>>> getService(ObjectLocatorImpl.java:43) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.util.InternalUtils$ > >>>> 22.run(InternalUtils.java:1429) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.OperationTrackerImpl. > >>>> run(OperationTrackerImpl.java:56) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.run( > >>>> PerThreadOperationTracker.java:60) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.RegistryImpl.run( > >> RegistryImpl.java:1254) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.util.InternalUtils. > >>>> extendPlanForInjectedFields(InternalUtils.java:1419) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.util.InternalUtils. > >>>> access$200(InternalUtils.java:50) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.util.InternalUtils$ > >>>> 20.invoke(InternalUtils.java:1380) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.util.InternalUtils$ > >>>> 20.invoke(InternalUtils.java:1366) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.OperationTrackerImpl. > >>>> invoke(OperationTrackerImpl.java:82) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke( > >>>> PerThreadOperationTracker.java:72) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.RegistryImpl.invoke( > >>>> RegistryImpl.java:1260) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.util.InternalUtils. > >>>> createConstructorConstructionPlan(InternalUtils.java:1363) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.ConstructorServiceCreator.getPlan( > >>>> ConstructorServiceCreator.java:52) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.ConstructorServiceCreator. > >> createObject( > >>>> ConstructorServiceCreator.java:62) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.ReloadableServiceImplementatio > >>>> nObjectCreator.createInstance(ReloadableServiceImplementatio > >>>> nObjectCreator.java:54) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.AbstractReloadableObjectCreato > >>>> r$1.invoke(AbstractReloadableObjectCreator.java:136) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.OperationTrackerImpl. > >>>> invoke(OperationTrackerImpl.java:82) > >>>> 2017-05-08 07:31:02 ERROR Registry:208 - Duplicate method > name&signature > >>>> in class file $Session_350f95bde0b5 > >>>> at > >>>> org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke( > >>>> PerThreadOperationTracker.java:72) > >>>> 2017-05-08 07:31:02 ERROR Registry:209 - Operations trace: > >>>> at > >>>> org.apache.tapestry5.ioc.internal.RegistryImpl.invoke( > >>>> RegistryImpl.java:1260) > >>>> 2017-05-08 07:31:02 ERROR Registry:218 - [ 1] Reloading class > >>>> dbla.dbla.controller.TraceImportController. > >>>> 2017-05-08 07:31:02 ERROR Registry:218 - [ 2] Creating plan to > >>>> instantiate dbla.dbla.controller.TraceImportController via public > >>>> dbla.dbla.controller.TraceImportController() > >>>> 2017-05-08 07:31:02 ERROR Registry:218 - [ 3] Calculating possible > >>>> injection value for field > >>>> dbla.dbla.controller.TraceImportController.hibernateSession > >>>> (org.hibernate.Session) > >>>> 2017-05-08 07:31:02 ERROR Registry:218 - [ 4] Creating proxy for > service > >>>> HibernateSession > >>>> at > >>>> org.apache.tapestry5.ioc.internal.AbstractReloadableObjectCreato > >>>> r.createInstance(AbstractReloadableObjectCreator.java:129) > >>>> at > >>>> org.apache.tapestry5.ioc.internal.AbstractReloadableObjectCreato > >>>> r.createObject(AbstractReloadableObjectCreator.java:121) > >>>> at $ControllerInterface_350f95bde0af.delegate(Unknown Source) > >>>> at $ControllerInterface_350f95bde0af.execute(Unknown Source) > >>>> at $ControllerInterface_350f95bde0ad.execute(Unknown Source) > >>>> at dbla.dbla.DbLogAnonymizer.main(DbLogAnonymizer.java:19) > >>>> > >>>> > >>>> --------------------------------------------------------------------- > >>>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > >>>> For additional commands, e-mail: users-h...@tapestry.apache.org > >>>> > >>>> > >>> > >>> > >> > >> --------------------------------------------------------------------- > >> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > >> For additional commands, e-mail: users-h...@tapestry.apache.org > >> > >> > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org > > -- Dmitry Gusev AnjLab Team http://anjlab.com