I want to create a JSF project with JPA. I am using eclipse juno 4.2 How can I integrate both in one project?
I read somewhere that keeping JSF and JPA project separately is a good practice, but I don't know how to do this. If I am using two different projects that is for JSF one project and JPA another how do I integrate and make it working depending on each other?
In the properties of the JSF project, add the JPA project as Deployment Assembly. This way the JPA project will end up as JAR in /WEB-INF/lib of the JSF project, which is exactly what you need after all.
Further you should make sure that you haven't fiddled/messed around in Build Path property in an careless attempt to solve this. If you changed anything there, make absolutely sure that you undo it.
Related
I work on a large Spring/Struts project in Eclipse. One thing I have to do frequently is dig through the spring.xml file so that I can update the definition for the class that I am working on. It seems like there should be an easy 2 or 3 click way to go from the Java class I am in to the Spring definition.
I have SpringSource installed, but this doesn't seem to offer anything that's actually useful to me. Does anyone know if this is possible in Eclipse and how to do it?
Bonus Question: is it possible to jump from a Struts Action class to it's corresponding struts.xml definition in Eclipse?
in your eclipse project, just add the spring nature. Right click the project and select the Spring Tools option -> Add Spring Nature. This will ensure eclipse keeps your java classes and spring context in synch.
I am trying to created a new java project. I have tried various examples available on the web but my project works sometimes and doesn't rest of the time. It seems that there happens some error which is not thrown when hibernate is doing a secondPassCompile() after creating factory.Can someone tell me a good resource to follow or give me some pointers on where I might be going wrong?
Is there any particular reason for using Tomcat? If you are trying to learn Eclipse with Hibernate as the JPA implementation, I would suggest you use JBoss as the app server. That way you can learn EJBs along the way if you prefer. If you want to learn just Eclipse and JPA there is no need to use any server - JPA can be practised just in JavaSE.
EDIT: Recently I had to create a simple JPA project. This is what I did: Create a new Java Project in eclipse. Download Hibernate 3.6.1 from http://www.hibernate.org/downloads. From the download directory take the Hibernate.jar and from the jpa directory take the one jar there. Take all the jars from lib\required. Add the above to your buildpath. Add logback jars - classic and core jars. For the database I used HSQLDB. Just one jar hsqldb.jar. Thats it! Enjoy JPA from here onwards.
I have found the slides at http://www.coreservlets.com/ very useful when trying to get up to date with EJB3/Hibernate and JSF. Complete and yet simple enough that you do not get ovewelmed by pages and pages of sample code. I wish they had something like that for MFC.
They have materials about Hibernate, I would definitely look at them.
About the JBoss issue, it is interesting if you plan to go into EJB3 later. It is not difficult to have a basic configuration working and, on top of that, it is based in Tomcat.
That said, if you are new to Hibernate, I would definitely test it first in JavaSE and then later go with it in a server (Tomcat or whatever).
I am new to Java world but I am pretty good at using Flex, actionscript 3, Ant and even Maven to some extent. Now I would like to learn some java and use Hibernate and JBoss (webapp).
I already have Maven working and have found the m2eclipse plugin on the web, it seem pretty nice for maven integration.
Now I would like to know how to set the project using "best practices" if possible and start the ball rolling. My question is not about using Java or Hibernate, it is just about project settings / configuration using m2eclipse or maybe another tool if necessary.
Thank you in advance for your help.
Actually, archetypes are not m2eclipse specific, they are maven species. But this was just a side note. Now, to answer your question, there is "sadly" no unique option and I hope I won't make things more confusing at listing them:
You could simply use the maven-archetype-webapp archetype to create a blank webapp and setup the Hibernate stuff yourself (follow the Hibernate tutorial which is maven based).
You could create a more specialized webapp (using the struts2-archetype-starter or the wicket-archetype-quickstart or a MyFaces archetype) and setup the Hibernate stuff yourself.
You could use the javaee5-maven-archetype archetype to create a Java EE 5 (JSF 1.2 + EJB 3) application.
You could use the softeu-archetype-seam archetype to create a JBoss Seam application (JSF+Facelets+Seam).
You could use one of the numerous AppFuse archetypes (Hibernate, Spring and the presentation framework of your choise) to create an "AppFuse" application.
If you want some guidance, my recommendation would be to go for an AppFuse archetype.
Choose a presentation framework and pick up the corresponding archetype. If you want a more "naked" solution, generate a blank webapp and setup hibernate yourself (follow the mentioned tutorial).
As I understand, using modules allows us to control some dependencies.
I mean that we can allow one module to interact with another one but not vise versa. We also can make some reusable things and we can make deploying easier, if, for example, put all tests stuff into a separate module and won't deploy it to production.
I haven't ever use modules but if described things are really possible I'd like to know how to make them.
How to set dependencies?
How to do this without IDE and any tools?
How to do it in IntelliJ IDEA?
Managing the dependencies yourself can quickly get complicated for non-trivial applications. For dependency management in Java, I suggest looking at Maven. Using the "test" scope you can bundle the project without all of the testing code. IntelliJ, like other populate IDEs, has built-in support for Maven.
Maven - Introduction to the Dependency Mechanism
Hope it helps!
in IntelliJ,you can select the module and right click it,and set the properties(include dependencies) for the selected module.
I have classes that are named exactly the same across different plug-ins that I use for my application, and I'd like to be able to configure them properly with Hibernate. The problem is that it looks like Hibernate dynamically generates a class' package name when trying to find a class when it's doing its mapping. With one plug-in this scheme works, but across multiple plug-ins it's not working. It looks like Hibernate gets confused when dealing with Hibernate configuration files across multiple plug-ins.
Is this because each plug-in has its own class-loader? What is the best way to proceed to make this work with the existing plug-ins and Hibernate?
The problem is, that every plugin has its own Classloader and Hibernate uses Reflection to find the right classes.
I have a very nice article at home about exactly this problem, but this one is in German. I will try to explain what you need to do.
In order to have the datastructure shared over several plugins, you have to put it in a plugin and enable a feature called buddy-policy.
Lets say you have a main-application-plugin which is initiating hibernate on startup, this plugin needs to "see" the classes from the datastructure-plugin. To do this the main-plugin sets its Buddy-Policy to "registered" and the datastructure-plugin registers itself as a "buddy". Unfortunately you have to do this all directly in the manifest file, at least in 3.3 there was no way to do this in the editor.
Once this buddy-policy works, Hibernate will also.
I looked up my old application and here is how I did it.
The main-application (toolseye.rcp) is dependent on the hibernate plugin (de.eye4eye.hibernate) and the datastructure-plugin (toolseye.datastructures)
The hibernate-plugin specifies its buddy-policy as "registered"
The datastructure-plugin registers itself to the hibernate-plugin
Here are the important lines:
Hibernate-plugin de.eye4eye.hibernate
Eclipse-BuddyPolicy: registered
Datastructure-plugin toolseye.datastructures
Eclipse-RegisterBuddy: de.eye4eye.hibernate
Put those line directly in the MANIFEST.MF
Both plugins need to reexport their packages in order that the main application or whatever layer you have in between can use them.
Hope that helped.
Just to make this complete.
Instead of using Hibernate, EclipseLink could be used as JPA-provider in a Eclipse RCP application. EclipseLink is the former TopLink from Oracle and has been choosen to be the reference implementation for JPA 2.
The point for an RCP is, that EclipseLink is available as OSGI-Bundles (org.eclipse.persistence.jpa), and due to that it can load classes from another plugin without an additional buddy-policy.
Currently I was playing around, using the following project structure (Model-View-Presenter Pattern). The names in the brackets specify the dependecy plugins (not all are included, only the ones related to this question)
rcp.mvp.view (rcp.mvp.presenter /
rcp.mvp.model)
rcp.mvp.presenter (rcp.mvp.data -
data reexports the model, so this is
not needed here) *
rcp.mvp.data (rcp.mvp.data.mysql /
rcp.mvp.model / javax.persistence /
org.eclipse.persistence.jpa)
rcp.mvp.data.mysql - provides only
the mysql-jdbc-driver. has to be
inside the classpath
rcp.mvp.model
In this scenario, the JPA provider in the data-plugin is able to load the classes from the model-plugin without a buddy-policy.
*Note, the presenter is not dependent on any JPA packages since this is encapsulated by DAOs (the main reason why to use them still)
Links
User Guide
RCP example (unfortunately not using DAOs)
EclipseLink conceptual Webinar from live.eclipse.org