aspose file tools*
The moose likes Object Relational Mapping and the fly likes what jars are needed for jpa using hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "what jars are needed for jpa using hibernate" Watch "what jars are needed for jpa using hibernate" New topic
Author

what jars are needed for jpa using hibernate

satish bodas
Ranch Hand

Joined: Jun 19, 2008
Posts: 116
Hello ,

For many days have been trying out examples using eclipse EJB project .

As a result have become totally ignorant regarding the exact jars needed in classpath .

I dont have the eclipse setup on my home pc .

I was wondering ...... obviously I would need Hibernate jar file

However I am not sure what would be the jar for JPA
( Since it makes use of classes like EntityManager - from which JAR do these do these come from )

Once I am at my office desk and the eclipse project - will dig further .

Thanks ,
~satish
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

versions left off for brevity.

antlr
asm-attrs
asm
cglib
dom4j
ejb3-persistence
hibernate-annotations
hiberate-common-annotations
hibernate-entitymanager
hibernate-validator
hibernate3
javassist
commons-beantils
commons-collections
commons-dbcp (if using this for connection pool)
commons-pool (if using dbcp)

you will also pssibly want caching jar's but that depends on the caching API you intend to use.


GenRocket - Experts at Building Test Data
Csaba Csurja
Greenhorn

Joined: Jul 24, 2008
Posts: 1
Hello,

I would suggest to download Eclipse 3.3 J2EE and Jboss 4.2.x.

After starting your Eclipse you can define a new Server (Window->Preferences->Server ->add Jboss 4.2)

If that is ready then once you create new EJB Project or JPA project your jars will be added to your project....
so no need to worry about it..

Regards,

Csaba
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

On my website I have a little tutorial on how to set up hibernate, and I've got an image of my _hiblib folder that has all my Hibernate jar files, including the ones used by Hibernate annotations and the JPA implementation. I even threw in my JDBC drivers for connecting to MySQL database as well.

Here's a look at what I've got. Does your classpath look similar?



Tutorial on How to Set Up a Hibernate Environment on Windows XP

-Cameron McKenzie
satish bodas
Ranch Hand

Joined: Jun 19, 2008
Posts: 116
Thanks Cameron for the details and also thanks to Csaba and Gregg

I am so used to eclipse that it scares me to work without it

I feel sometimes its good to get down and dirty on the prompt minus any tools

And to my embrassment I am facing issues while setting up some classes correctly in the classpath .

I will complete that exercise and post the list that came up with .

Thank you
~satish
satish bodas
Ranch Hand

Joined: Jun 19, 2008
Posts: 116
OK finally got a simple example of JPA ( using Hibernate ) to run from the prompt .

My list of jars required ( at run time )were ::


To compile the code ::


To run the code ::


Surprising regarding the difference between the number of files required for compilation as compared to running the code .

Not using caching or connection pooling so none of the additional jars are specified here .

I kept adding one jar at a time till the example ran successfully .

One thing I didnt understand was ::
On one of the exceptions - I needed to add the jar - " hibernate-entitymanager.jar "

On next run got an exception for which I had to add the following jar - " jboss-archive-browsing.jar "

This is a little puzzling
I know Jboss and Hibernate are both under Red Hat - but why would one product ( Hibernate ) jar be dependent on another product ( Jboss ) jar ?
Is that an oversight ?

Also didnt understand why my code is running when the config file - "persistence.xml" located under "META-INF" is not on the classpath ?

Thanks ,
~satish
[ July 28, 2008: Message edited by: satish bodas ]
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

If you put all of your jar files in a common directory, and you're using Java6, you can use a wildcare in your javac compile and java runtime command statement:





In this case, all my jar files are in the C:\_hiblib directory.

The setup is detailed in this tutorial:

Setting Up Hibernate: A Simple Tutorial

-Cameron McKenzie
satish bodas
Ranch Hand

Joined: Jun 19, 2008
Posts: 116
Thanks Cameron for your inputs

I am in Java 5.0 - so I take it that I will have to type out the complete path for each jar ?

also I am confused why my code ran when I didnt specify my "persistence.xml" file in classpath .

Thanks ,
~satish
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Surprising regarding the difference between the number of files required for compilation as compared to running the code .


Well, for Annotations, you only need the jars there for compile time. They are not needed for runtime, except when you have jars that will react on those specific annotations. What that means is I can personally create a bunch of annotations that you would need the jar for to compile, but if you didn't want to use my framework while running, like you just decided to change environments, then you can still use/run the compiled code with my annotations without having the jar that contains those annotations.

That way Annotations are not tightly coupled to your code, they are just markers of information.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
satish bodas
Ranch Hand

Joined: Jun 19, 2008
Posts: 116
Thanks Mark for the details .

I need to post queries properly to prevent the huge horizontal scroll !

Last question - why did they introduce dependies of one product jar on another product jar ?



Thanks ,
~satish
Vallaru smitha
Ranch Hand

Joined: Aug 19, 2008
Posts: 87

Hi,

I have added all the jars as mentioned in the above post but still i am getting an error

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
at org.slf4j.LoggerFactory.<clinit>(LoggerFactory.java:60)
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:151)
at org.hibernate.ejb.Ejb3Configuration.<clinit>(Ejb3Configuration.java:107)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:124)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
at com.foo.HelloWorld.initEntityManager(HelloWorld.java:21)
at com.foo.HelloWorld.main(HelloWorld.java:14)
Caused by: java.lang.ClassNotFoundException: org.slf4j.impl.StaticLoggerBinder
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 8 more




Could anyone please point me to a working example of JPA\

Thanks



Vallaru smitha
Ranch Hand

Joined: Aug 19, 2008
Posts: 87

hi, I did some digging but still not able to resolve the error i am getting is

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" javax.persistence.PersistenceException: Unable to configure EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:265)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:125)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
at com.foo.HelloWorld.initEntityManager(HelloWorld.java:21)
at com.foo.HelloWorld.main(HelloWorld.java:14)
Caused by: org.xml.sax.SAXParseException: Content is not allowed in prolog.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at org.hibernate.ejb.packaging.PersistenceXmlLoader.loadURL(PersistenceXmlLoader.java:70)
at org.hibernate.ejb.packaging.PersistenceXmlLoader.deploy(PersistenceXmlLoader.java:89)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:222)
... 5 more
Does anyone have any idea to resolve it
Simon Prinzleve
Greenhorn

Joined: Mar 03, 2009
Posts: 3
Hi Vallaru,

I got the same errors - especially the ones about the slf4j.

Adding the right jars for slf4j solved the error.
(They are somehow called from inside hibernate - adding a catch(Throwable ...) inside my HibernateUtil brought me to the solution)

In your case you seem to have the jar available - but especially the LoggerFactory should just appear once)

The details are described here:

http://liferay-portlets.blogspot.com/2009/03/problem-could-not-initialize-class.html

Hope it helps,

Simon


Check http://liferay-portlets.blogspot.com
Ryann Ong
Greenhorn

Joined: Jan 24, 2010
Posts: 19

I am also new to hibernate but i think you need to use slf4j library and log4j library. If im not mistaken, these two libraries are used for logging and console output for hibernate. Try adding them to your libraries or classpath as well
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

Just as an update to this little thread, I thought some people might be interested in some changes to the required jar files from Hibernate 3.3 or whatever to Hibernate 3.5. I've posted on this JavaRanch thread, but I thought I'd put it here for quick reference.

The screenshots were taken from this tutorial, which includes some CBT videos as well:

Slingshot Yourself into Hibernate 3.5

But here are the key points for working with Hibernate 3.5:

Download the core distribution files. You can find these at hibernate.org, although I believe they redirect you to a download site.



"When you download this zip file, the hibernate3.jar file will be in the root folder of the download. The hibernate-jpa JAR file will be in a subfolder named jpa. The other JAR files, with the exception of slf4j-simple-1.5.8.jar, will be in a folder named required. "


People often miss the slf4j file:



Once I'm done, my eclipse environment looked something like this:



I've got the MySQL jar file in there too, but you may have whatever JDBC jar you need. And while this screenshot was taken from Eclipse, what's important is all of the Jar files. These are the various JAR files you need to be able to link to at runtime in order to get your Hibernate 3.5 code, which supports JPA 2.0, working properly.

-Cameron McKenzie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what jars are needed for jpa using hibernate