Using tapestry-jpa just with tapestry-ioc in non-web project - jpa

this is a very basic question, and I'm kind of sorry, but I don't seem to be able to get a simple Tapestry-IOC based application to work with the built-in Tapestry JPA module.
The application is not necessarily meant as a web project so the dependencies are just tapestry-ioc and tapestry-jpa for the JPA integration. I used the hibernate-entitymanager before and everything worked fine. But I thought I might rather use the official JPA support of Tapestry.
So what I did was to get the above mentioned dependencies (in Tapestry version 5.3.7) and to write the beginning of a test.
This beginning looks like this
Registry registry = RegistryBuilder.buildAndStartupRegistry(MyModule.class);
EntityManager em = registry.getService(EntityManager.class);
That's all. Because as soon as I try this I get the error that no service would implement the EntityManager interface.
So I added the Tapestry JPA module:
Registry registry = RegistryBuilder.buildAndStartupRegistry(MyModule.class, JpaModule.class);
But then again I get an error that the JpaModule wants to contribute to the ApplicationStatePersistenceStrategySource service which is not present. This service seems to be defined in the TapestryModule so I did
Registry registry = RegistryBuilder.buildAndStartupRegistry(MyModule.class, JpaModule.class, TapestryModule.class);
But this causes an error due to the missing servlet API. So now I get to the point where I would have to define the web environment for Tapestry. But I don't want this, I just wanted to use the JPA integration.
Is this even possible? And if so, how do I do it? Following the documentation at http://tapestry.apache.org/integrating-with-jpa.html does not help in this regard.
Thank you very much for reading, any hint appreciated!

Quick answer -- I could be wrong -- but I thought Tapestry-jpa was intended for using JPA with Tapestry-core (the web framework). I don't think there would be any benefit over plain JPA in your case.

Related

Adding transaction support to embedded jetty/GWT RemoteServiceServlet without Spring?

GWT's servlet implementation has onBefore/onAfterDeserialization which would give me a hook with which to start and stop transactions without doing anything fancy, however those methods don't allow me to properly check for error conditions after the service method got invoked, I just have access to the serialized return value, not directly to any exception that might have been thrown, so deciding whether to roll back or not is not possible that way without rewriting parts the GWT servlet.
I was thinking about using aspectj's compile-time weaving. However, this does not work with Netbeans' compile-on-save feature because the module needs to be recompiled using the aspectj compiler.
How about LTW (load-time-weaving)? Is there any way (or example) to add LTW to the webapp container without using the Spring framework?
I was also thinking about using AOP based on Java dynamic proxies, ie. to put a proxy in front of the servlet. Again, the question arises how to tell the Jetty WebApp container to load the proxy instead of the original servlet.
Or is there any ready-to-use solution out there already?
I think you could overwrite a combination of
public String processCall(RPCRequest rpcRequest) from RemoteServiceServlet and RPC.invokeAndEncodeResponse to do what you want.
Not ideal, as you need to copy/paste a few lines of code, but they really are only a few.
I myself hit the same problems as I needed some customizations, and relevant methods didn't had the access modifier that I needed, so I ended up copy/pasting some portions.
I can't comment on the rest of your question, but I don't expect to find any ready-to-use solutions, as GWT-RPC doesn't seem to have any new fans out there; just people maintaining legacy systems. Therefore, I expect that you either don't find anything or find solutions that are no longer maintained.

Does anyone know where I can find current information on adding h2 persistence to a RCP e4 app?

I would like to add some persistence to save some application data and I feel like I have searched the web for days without any success.
I have found some older links and the eclipse Gemini project. However, I suppose I am too new to understand the implementation or it is just a little dated. Probably, more of my lack of knowledge.
Anyway, is anyone willing to point me to a working example and/or provide me with some assistance offline?
If you want to use H2 with plain JDBC, you won't need the Gemini project. In this case you can wrap the H2.jar with the corresponding JDBC driver in a single bundle (plugin) and implement your db access there.
The Gemini project is for using persistence via JPA, which works with any JDBC capable database.
In either case, be aware that in an OSGi environment like Eclipse RCP, there is one classloader per bundle. This leads to lots of complications. We are using Hibernate as JPA engine within our E4 application and we cannot split the JPA configuration, the JPA engine and the entity beans :-(
We tried using EclipseLink as JPA engine but this doesn't work on all our entities :-(
I found this blog article by Raja Kannappan which briefly explains class loading in OSGi.
You can read more about JPA in The Java EE Tutorials (although JPA is part of Java SE, too).
Hope this helps.

Osgi a container or framework

Hi I am a newbee to osgi . Could anyone please help me understand that whether osgi is a container or framework? Can anybody please explain the difference between the two as well. Thanks it will be a great help.
It depends what you mean by those terms, there's no universally-accepted definition of either.
From my perspective, OSGi is not really a container since it does not wrap around your code or change the execution model. So I prefer the term framework, and indeed most of the documentation refers to it as "the OSGi Framework" or sometimes "the OSGi Service Platform".
For example: you can create a running and useful OSGi Framework in just 5-10 lines of Java code.
I would define a framework as a library that you code against and that has control over the execution. So e.g. spring is a framework and OSGi in the same way.
A container is a generic application you can start up and where you can deploy executeable artifacts. OSGi by default does not allow you to deploy artifacts. It mainly provides and API that allows you to load and start bundles. In practice though pretty much all OSGi implementations allow deployments like from a certain directory. So at least the implementations are also containers.
Like Neil wrote my definition is not the only one so the above may not be universally true.

Spring Data JPA and SimpleJPA/SimpleDB

I'm wondering if it is possible to specify SimpleJPA as the persistence provider used by Spring-Data-JPA. I'm not a JPA expert so I hope this question isn't silly. Is it as easy as just specifying SimpleJPA's entity manager factory in the persistence.xml? I have yet to find anywhere online where someone has used Spring-Data-JPA to connect to Amazon's SimpleDB, I would love it if someone could point me in the right direction.
I just found this project and got it working for our Spring Data + SimpleDB needs:
https://github.com/3pillarlabs/spring-data-simpledb
The documentation is pretty good and getting things up and running was pretty straight-forward. I was accessing SimpleDB via Spring Data with about 10 minutes of work.
Generally setting up your persistence provider is just a matter of setting up the EntityManagerFactory through your Spring context (in case you use the Spring container). Thus have a look at how to configure EntityManagerFactory instances in Spring.
There might be the need to implement a custom JpaVendorAdapter to let Spring use the SimpleDB JPA implementation correctly. For some advanced functionality (e.g. using pagination with manually defined queries) we'd have to tweak the Spring Data JPA codebase a bit. If you'd like to see that supported feel free to open a ticket in our JIRA.

GWT+hibernate for highly interactive web application?

As a Java developer new to the web development environment, I was quite excited to find Grail which provides a great framework especially the convenience of abstracting DB operations with ORM. I later learned that it is actually the function of hibernate. At the same time I am delighted to learn about GWT. It is a god send for the project. I can continue building applications with event driven widgets using Java. Yeah!!
The answer seems clear: GWT + Hibernate. Will it work? What do I miss? Why there is much talk about this set up? What is the concern or area of risk? Have anyone tried this before?
Or, how do GWT developers handle the challenge of data persistence? What are the options?
Also I can't seem to find a good tutorial about setting up Hibernate with Eclipse -- the IDE I am familiar with. What are the tools or plug-ins needed?
Hibernate works fine with GWT as long as you keep in mind that the GWT code is actually running on the browser so you can't manipulate Hibernate objects in your client code. The downside to that is you're probably going to have duplicate objects on the client and server side, but you can use course-grained DTOs via the GWT remote procedure calls. On the server side, just create a ServletListener to initialize your Hibernate project and then use normal Hiberate methods to store and retrieve objects.
As far as Hibernate and Eclipse, Hibernate has an Eclipse plugin, but it's not really necessary to develop in Eclipse. It gives you the ability to run HQL and to reverse engineer Java objects from the database or vice versa, which can be useful, but it's not required.
If you want to go the hibernate way, you should have a look at Gilead or its predecessor hibernate4gwt. It works pretty well, but documentation is a bit sparse.