Hibernate without Java EE 6 - java

I have Websphere 7 server, and it don't support JPA 2.0. So I can't run on WAS 7 JPA 2.0 applications.
But I'm wondering how Spring users run Hibernate on Tomcat or Jetty? This servlet-containers also (as WAS 7) doesn't support Java EE 6.
So it's mean that I can run Hibernate on WAS 7 with the same results as on the Tomcat or Jetty?.
If yes, what are benefits of using app-servers for JPA? Why all developers don't use servlet-containers instead app-servers?
Also I heard about "container-managed" stuff, that allows some additional features and functionality. So it's mean that many developers (who uses Spring on Jetty and Tomcat) don't get benefits of using container-managed features of app-servers?
P.S. I know about available Feature Pack patch for WAS 7 for JPA 2.0 support, but question not about it.

You can bring in a lot of functionality by including the appropriate jars in your WEB-INF/lib folder, but then the servlet container cannot help you in any way with the functionality, and it will most likely not be well integrated with the functionalty actually provided by the container. A typical example is bringing your own JSF 2.0 libraries.
The real advantages of using implementations in the container, is that the container can then help with clustering across multiple hosts, providing JDBC connection pools, etc.
So, you need to be more careful when including e.g. Hibernate yourself, and do all the configuration inside your own deployment, but it can be done.

You could just as well ask an exactly opposite question: "why use bare servlet containers with JPA 2 since it is included in all the Java EE 6 servers?".
Basically it boils down to either:
having a light-weight container and then a heavy application (the Spring way),
having a light-weight application and then a heavy container (the Java EE 6 way).
After years of evolution, the models of building the applications with Spring and Java EE 6 have converged to the point where sometimes you cannot really tell just by looking at a class, whether it's a Spring or a CDI bean. So the real difference is mostly in configuration.

Application servers offer a set of services "out of the box", so they are easier to use if the offered services are the ones you need. You just package and deploy your application and the thing works. Furthermore, most of the technologies are instantiated by the application server, so you avoid a lot of classloader issues.
The problem with application servers is that sometimes (quite often, actually), you need to pick and choose particular versions of particular frameworks, services, etc that are incompatible with those which the application server offers. In those cases, you usually need to fiddle with the application server, and in some cases, what you would like to do might not even be possible with your application server.
For example, Weblogic 10.x is a Java EE 5 application server and so it will offer by default JSF 1.2 and JPA 1. If you want to use something newer, you need to manually deploy some additional libraries (JSF 2.0), or patch the server (JPA 2.0).
Another example: with Glassfish 3.1 I have not been able to use Tomcat EL intead of Glassfish EL. Tomcat EL supports varargs method call while Glassfish EL does not.
That rigidness of Java EE application servers makes a lot of people prefer developing for a standalone servlet container such as Tomcat or Jetty, where you have nothing out of the box but the Servlet and JSP APIs, but you can manually put everything inside. You can also package it with your application, which is more comfortable when you are developing, but can give you problems if you deploy more than one application per container (waste of resources, classloading issues, classloader leaks, ...)
UPDATE:
There are some differences in using JPA in a SE environment (such as Tomcat) when compared to using JPA inside a Java EE container. Basically:
You have to manually manage EntityManagerFactory and EntityManager instances.
Tomcat does not do injection so #PersistenceContext annotation and similar ones do not work.
Note that some containers (such as Spring) can be configured to hide these details, so you can work exactly as if you were inside a Java EE container.
Read the JPA spec for details on running in SE environments instead of EE environments.
Regarding another libraries, in general you will find some minor differences. For example, JAX-WS requires registering a servlet and a listener for your webapp, but anything else should be identical. Usually you can search the documentation for instructions on how to run the thing inside a standalone servlet container.

There is a JPA 2.0 feature pack for WAS 7.0, which may help you.

Related

Why servlet container not preferred over spring IOC container?

Servlet container implements web component contract of Java EE specification, specifying a runtime environment for web components that includes security, concurrency, lifecycle management, transaction, deployment, and other services.
Apache tomcat is one open source example.
Object satisfying the contract given by javax.servlet.ServletContext, is used per each web application
Spring IOC container also implement web component contract of Java EE specification.
Object satisfying the contract given by org.springframework.context.ApplicationContext, is used per each web application
Why Spring IOC container is preferred over servlet container?
There are many problematic statements in this question, I'll try to do my best to clarify few things by adding some "list" of facts that hopefully will help:
Tomcat does not implement JEE specification, in fact, its famous only for implementing small (although important and widely-used) specification under the umbrella of JEE: servlets (and JSPs which a technically a servlet but in a more HTML like form).
That's true that tomcat also follows a deployment model of WARs described in JEE, but in JEE there are much more types of archives that tomcat has nothing to do with. In addition, recent versions of tomcat allow "embedded mode", where you don't have to work with WARs at all.
Spring, in a nutshell, is an IOC container, something that tomcat doesn't cover at all. I assume you know what is IOC, so I won't dig into IOC in this question.
In addition to IOC, spring provides a fairly good integration with many different technologies (think about it as yet another thing that Spring can do). Now among these technologies, you can find Web Framework (called spring MVC), various templating engines (just like JSP), REST, working with database (Spring Data), Security model (Spring security) and many other things.
All this makes spring a competitor of any implementation of JEE specification. Spring conceptually makes everything that JEE does (and arguably even more) but doesn't follow the standards established by JEE. Having said that, in modern versions, the difference becomes less and less significant, in many cases, Spring does honor interfaces and annotations offered by JEE, in addition to its own way to do stuff.
So, now it's obvious that Spring and Tomcat don't really compete with each other. In fact, they can work together and its a really wide-spread tandem:
One can use a spring framework to develop an application that will run on tomcat.
Another successful model is to use spring boot that allows embedding the tomcat into the spring boot application and use it under the hood to server web (HTTP/Rest) requests.
Hope this sheds some light and helps to understand the differences between Spring and Tomcat

Containers for a Spring Project

I would like to take a doubt about the container to run a "Spring Application", in my opinion one of many features who Spring Framework offer is a possibility to create application without container EE. Is right use this type of container ("WildFly", "GlassFish") with a spring project ? In my option is wrong but i'm open to listening more people.
i saw a article where the author are showing the features of Spring 4 with the WildFly, but i didn't agree, so i would like to take more opinions about this topic here.
Considering Spring Web and Web MVC you will typically use a lightweight container like Tomcat, Jetty or any other servlet container - maybe embedded like Spring Boot does.
Spring Web is designed to work without a full JEE container but will also work deployed inside one.
With Spring without JEE you have much more control about the features you use. A full appserver has a bundled feature list, you get all or none. Spring offers you to pick what you need resulting in a more slim application.
Well, first of all it is a little tricky to say that "something" is wrong or right in software development, mainly in this type of subjective question. As always, that really depends on what you need and on the EE Container that that you are using.
Let's get Widlfly as example. Since JBoss 7 (and now Wildfly) I do not think we can say that JBoss is a "heavy" Server, as it starts in just a few seconds, much faster than in the earlier versions. While it is true that Wildfly comes with a lot of services that you may not use, it is not correct to say that you get "all or none", for at least 2 reasons:
You can disable the services you do not need.
Wildfly works with the concept of lazy-loading for its services, which means that it will only load the services that are required to run a given application.
Having said that, we can not forget that Spring also uses some EE services, if you want to. So, if you need to use Spring with JMS, for example, you still need a JMS container. In this case, you can use an EE Server without needing to install additional services or you can start a JMS container in your Tomcat.
Besides the EE features, there is also the question of features related to the server, such as configurability/manageability (Web interface, CLI), HA, scalability... that really varies from server to server and I think Jboss 7/Widfly does a good work on these points.

CDI and Bean Validation in Java EE 5 Application Server?

CDI and Bean Validation are Java EE 6 Standard Specifications. Nevertheless, I can use both within Java EE 5 Application Servers (and also within Java SE) by just adding the libraries to the project.
Is this correct?
Are there any disadvantages of using both in Java EE 5 application servers instead of Java EE 6 application servers?
I have to use the Oracle 11 g Suite and JDeveloper. In the meantime, JDeveloper supports JSF 2.0, but I cannot find any support for Bean Validation or CDI. Nevertheless, this is not a problem. There is no IDE support (for code-generation, a step-by-step-guide, or whatever), but I can use these libraries by using the simple java editor. Right?
Java EE 6 is basically a collection of APIs. An application server is Java EE 6 compliant if it implements all those specifications. But you can still use the APIs in an Java EE 5 compliant application server. Some people even put EJBs into Tomcat, so technically that's possible. Still it makes sense to use a compliant AS, as it also provides all the services related to the specs.
I believe that's correct.
The disadvantage is that you're a version behind. You may have to modify your code if and when you decide to upgrade to Java EE 6 (e.g. new imports, etc.)
You can pretty easily add Apache OpenWebBeans or JBoss Weld (choose one of the 2 CDI implementations) to your WEB-INF/lib and register the servlet listeners in your web.xml manually. Voila, then you have CDI support!
For JSR-303 Bean Validation it's a bit more tricky, because only JPA2 and JSF2 makes use of it. So you would need to add Myfaces2 and Hibernate-3.5, EclipseLink2 or OpenJPA2 to your local jars and disable the container provided variants.

Java EE 6 vs. Spring 3 stack [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I'm starting a new project now. I have to choose technologies. I need something light, so no EJB or Seam. On the other hand I need JPA (Hibernate or alternative) and JSF with IceFaces.
Do you think that such a stack on Spring 3 deployed on Tomcat is a good choice? Or a Java EE 6 web application could be better? I'm afraid that Java EE 6 is a new technology, not well documented yet. Tomcat seems to be easier to maintain than Glassfish 3.
What's your opinion? Do you have any experiences?
I need something light, so no EJB or Seam.
Would you care to explain what makes EJBs heavy since EJB3? Do you realize that we are not in 2004 anymore? I'd really like to read your definition of light and your arguments (and I will update my answer with pleasure because I'm pretty sure I would have a few solid things to say).
On the other hand I need JPA (Hibernate or alternative) and JSF with IceFaces.
Java EE 6 Web Profile which includes JSF 2.0, JPA 2.0, Bean Validation, EJB 3.1 Lite, CDI,... would be perfect for this and you can use GlassFish v3 Web Profile to run an application built with the Java EE 6 Web Profile.
Do you think that such stack on Spring 3 deployed on Tomcat is a good choice? Or a Java EE 6 web application could be better?
Well, I like the idea to run my code on a non-proprietary platform (Java EE) rather than on a proprietary container (Spring). And I think that Java EE 6 is good enough (and this is an euphemism, EJB 3.1 (Lite), JPA 2.0, JSF 2.0, CDI kick ass). Note that I was a JSF skeptic but I took a second look and JSF 2.0 with CDI is so different that I can't even compare. And if you didn't look at CDI, let me tell you that it rocks.
I'm afraid that Java EE 6 is a new technology, not well documented yet.
Java EE looks pretty well documented to me. This sounds like free claim. And, believe me or not, I start to find Spring getting complicated while Java EE getting easier.
Tomcat seems to be easier to maintain than Glassfish 3.
Did you try something? Did you face any particular problem? Again, this sounds like free claim.
I have not used JavaEE6.
However, I have been beaten up badly enough by all the previous versions of JavaEE and EJB's that I won't trust it until it establishes itself as the de facto standard, not just the de jure standard. Right now, Spring is still the de facto standard.
Fool me once, shame on you. Fool me twice, shame on me. Fool me three times, EJB.
Some will claim that Spring is proprietary. I would argue that the vendor implementations of the JavaEE specs have been just as proprietary, if not more so.
I went through a major conversion recently of moving a bunch of Java Applications from JBoss to Weblogic. All of the Spring/Hibernate apps ported with zero modifications, because they had all the libraries they needed built in. All the apps that used JPA and EJB and JSF were a disaster to port. Subtle differences in interpretations of JPA, EJB, and JSF between appservers caused all kinds of nasty bugs that took forever to fix. Even something as simple as JNDI naming was completely different between AppServers.
Spring is an implementation. JavaEE is a spec. That is a HUGE difference. I would prefer to use a spec IF the spec was 100% air-tight and gave absolutely no wiggle room in the way vendors implement that spec. But the JavaEE spec has never been that. Maybe JavaEE6 is more air-tight? I don't know. The more you can package in your WAR, and the less you depend on AppServer libraries, the more portable your application will be, and that, after all, is the reason I use Java and not Dot-NET.
Even IF the spec was air-tight, it would be nice to be able to upgrade the appserver without having to upgrade all my technology stacks in all my applications along with it. If I want to upgrade from JBoss 4.2 to JBoss 7.0, I have to consider the impact of the newer version of JSF on all of my applications. I don't have to consider the impact on my Spring-MVC (or Struts) applications.
It doesn't matter. Java EE 6 is good enough and because of the profiles there, it is not "heavy" - you'll just be using the web profile.
Personally, I prefer Spring. But I'm running out of rational arguments against Java EE 6 :)
(As I was reminded by a comment - you might want to try RichFaces, as well as ICEfaces and/or PrimeFaces - depending on what components you need).
Recently, one of my client assignments involved evaluating Spring Stack Vs Custom framework stack Vs a Java EE Standards. After a month of evaluation and prototyping, I was not just happy but blown away by the Java EE 6 feature set. For any new "enterprise" project architecture in 2011 and going forward, I would go with Java EE 6 and potential extensions like Seam 3 or the upcoming Apache JSR299 extensions project. Java EE 6 Architecture is streamlined and incorporates best of many open source ideas that have evolved in the last several years.
Consider the following features out of the box: Event Management, Contexts and DI, Interceptors, Decorators, RESTful webservices, integrated testing with embeddable container, Security, and many more.
Most of my results are published in my blog explaining the key concepts of Java EE 6 that you might find useful.
Of course, there is no hard and fast rule for choosing a framework. Java EE 6 could be well bloated for simpler "web sites" that don't require a rich conversational session state. You might as well pick Grails or Play! Framework. But for conversational web applications, I can't see a better argument why Java EE 6 is not a good fit.
Now, after some time, I have experience with stacks :
Java EE 5 + Seam + GraniteDS + Flex
Spring 3 + Vaadin (on GWT)
Spring 3 + JSF 2.0 (PrimeFaces)
My colclusions are:
Spring 3 is much much simpler than Seam (almost Java EE 6) and runs on Tomcat and Jetty! (Jetty for developement with maven plugin is a trasure).
I love Flex (I actually was a Flex developer for long time so I'm biased) and if you need rich interface and can buy FlashBuilder use this, but use this wich Spring + GraniteDS or BlazeDs backend. If you can't buy FlashBuilder don't waste your time.
Vaadin is great!. Developement process is simpler than Flex, but you can create rich application easily without HTML mess. You wont't write a singe JS line. You just need some CSS (in Flex you need it too). So if your application interface is going to behave like desktop application and you can't (or dont want to) use Flex - use Vaadin. Warning! Vaadin has big JS overhead for browser.
If you create simpler website-like application use JSF2.0 (with spring backend as above). You'll need to fight with HTML (I hate it) and creating rich interface will be harder than Vaadin (especially layouts). You will get lightweight HTML for slower browsers/compuetrs. I like PrimeFaces - it's easy and well documented. Second place is IceFaces
If you create a website (NOT a web application) where you need to put life into HTML (instead of create enterprise application that fits into browser) use Wicket (if you prefer component based, pull attitude) or SpringMVC (if you prefer template based, push attitude) or just use Play! framework. Remember that creating rich data-based components will be much much harder but you will have control over each tag of html (your HTML/Graphics designer will love it)
Read Adam Bien's Future Of Enterprise Java ...Is Clear (Java EE with/without Spring and Vice Versa), including comments to get both sides of coin. I will choose Spring for several reasons and following is one of them (reproducing one of the comments from post)
'I am not sure which Java EE 6 server you are talking about. There is Glassfish certified and TMAX JEUS. It will take quite a while (read: years) until Java EE 6 compliant versions of WebSphere, WebLogic, JBoss etc are in production and can be used for real application. Spring 3 just needs Java 1.5 and J2EE 1.4 so can readily be used in almost all environments'
My opinion is based on something not mentioned by others, namely that code at my work tend to live for decades (literaly), and hence that maintenance is very important to us. Maintenance of our own code, and the libraries we use. Our own code we control, but it is in our interest that the libraries we use, are maintained by others in the above mentioned decades or more.
To make a long story short, I have concluded that the best way to achieve this is by using open source implementations of Sun specifications all the way down to the raw JVM.
Of the open source implementations Apache Jakarta has proven to maintain their libraries, and recently Sun has done a lot of work in producing high quality implementations for Glassfish v3. In any case, we also have the source for all modules, so if all else fails, we can maintain them ourselves.
Sun specifications are usually very strict meaning that implementations conforming to the spec can be interchanged easily. Just have a look at servlet containers.
In this particular case, I would suggest having a look at JavaServer Faces simply because it is part of Java EE 6 meaning it will be available and maintained for a very, very long time. Then we have chosen to augment with MyFaces Tomahawk as it gives some useful additions, and it is a jakarta project.
There is nothing wrong with JBoss Seam or others. It is just that their focus is less towards the maintenance issue that is so important to us.
I can see using Spring if you already have it, but for the new project, what's the point? I would go directly with Java EE 6 (ejb3, jsf2.0, etc.)
If the client is fine with Flex, go for it. Use BlazeDS or similar - no mvc. You might spend more time on that part (exchanging data between server and client) but you have full control on both sides.
Don't use Vaadin, unless you want to kill your browser. Plus, you spend more time on getting around the code once your pages become more complex. Also, your mindset will need to be completely changed and anything you know about standard front end development will be waste. The argument that you don't have to use HTML or JS doesn't make much sense. You still have to know it even if you don't use it. It renders to HTML and JS eventually. Then try to debug it - make sure you got few days for simple stuff. Plus, I cannot imagine web developer who doesn't know html/js.
I just don't understand why people are trying all those abstractions instead of using Java EE directly.
Why is there still rumblings about EJB being heavyweight in 2010? It seems people are not being updated in Java EE technologies. Just try it out , you will be pleasantly surprised how things are simplified in Java EE 6.
The answer to your questions depends on your project requirements. If you don't require the Java EE features like message queues, container managed global transactions etc then go with tomcat+spring.
Also from experience I have found that projects that require a lot of web service integration, scheduling, message queues are best best done using some of the Java EE stack.
The good thing is using spring you can still integrate with Java EE modules running in an application server.
Java EE 6 is very different from the previous releases, and it really makes everything lot easier. Java EE 6 combines the best ideas from the diverse Java community - for instance Rod Johnson from Spring framework was actively involved in the making of the Dependency Injection JSR in Java EE 6. A benefit of using Java EE 6 is that you are coding according to a standard, which could be important in some organizations for vendor support etc.
GlassFish v3 supports Java EE 6 and it is quite light-weight and starts up really fast. I have been using glassfish v3 for my developments, and it is really easy to configure. It comes with a very user-friendly admin console that lets you graphically administer your server.
If you are using GlassfishV3 and JSF 2, then you can take advantage of the CDI features of Java EE 6, that lets you easily create conversations (e.g. wizard like pages) in JSF.
Having said that, using Java EE 6 also requires you to learn a new API. Depending on the timeframe available it might not be the best choice for you. Tomcat has been around for ages, and the tomcat+spring combination has been adopted by many web projects, which means lots of documentation/forums are around.
I have worked in both Spring and Java EE 6. What I can say from my experience is that If you are going for the age old JSP or proprietary Flex then you are safe if you stay with Spring.
But if you are to move ahead with JSF then it's time to shift to Java EE 6. With Java EE 6 you are moving to Facelets and standardized script libraries and component libraries. No more script incompatibilities and component library matrices.
Regarding Spring MVC, it's good as long as your project doesn't grow too big. If it's a huge enterprise application stick on to Java EE 6. Because that's the only way you could maintain your own component libraries and resource bundles in an orderly manner.
If you need the Java EE full stack I recommend you GlassFish 3.1. It starts very quickly compared to other Java EE containers which implements some part or all Java EE 6 (JBoss 6, WebLogic 10.3.4), redeployment take seconds and almost all can be done by convention over configuration, it is very friendly.
I you want something "Light" you can customize an Apache Tomcat 7.x with the desired features. I used a lot with the following libraries:
Weld 1.1.0 (CDI)
JPA 2.0 (Hibernate 3.6.x) - only resource local transactions
JSF 2.x (Mojarra)
RichFaces 4.0
BIRT runtime
Been a Java EE developer for the past 10 years (I suffer early EJB, JSF and web technologies), Java EE 6 is very easy, well coupled and current hardware runs smooth so original reasons that motivated Spring are no longer valid.
I'd still prefer Spring.
And I'd pass on JSF. I think it's a dead technology. Spring MVC would be a better alternative. So would Flex. Think in terms of contract first XML services and you can decouple the back end from the UI completely.
I'd recommend Spring + Tomcat unless you can wait the time for glassfish v3 and Weld to become more mature. There are currently a few issues with memory consumption/cpu load when running glassfish with CDI enabled applications.
Didn't read everything but just to tell that you can now use EJB3 inside a war on Java EE 6 so you can use EJB3 on Tomcat (I think).
I recommended to you Tomcat with Spring because:
Spring can create backing beans for JSP
You will use Spring to persist object through JPA
It is good choice to choose Tomcat because you don't need any heavyweight processing

Using Spring Pitchfork to have Java EE compliant code that runs in non-Java EE container

I am facing the decision to abandon Java EE 5 container to use web container instead (with Spring). According to Interface21 Spring Pitchfork allows elements of the Java EE programming model to be used in Spring. Thus, I get a subset of Java EE annotations inside of Spring container. Since I prefer to maintain compatibility with Java EE this looks as attractive option to me. What is your experience with Pitchfork and what did you accomplish by using it?
No experience with Pitchfork, but lots with Spring. Foregoing EJBs hasn't been a problem. POJOs have been more than adequate.
Two other alternatives to consider:
You can use OpenEJB with Tomcat if you need EJBs, want to stick with Tomcat, and don't want to switch to a purchased or open source Java EE app server.
You can try Spring dm Server with OSGi. Eat the shell and the egg - go all the way.
I use pitchfork for unit testing EJB3 and JPA components outside of the container and it works really well. I can wire up everything I need including a transaction manager, a 2nd level caching provider, etc.

Categories