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?
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
posted
0
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 ?
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.
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.
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\
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
posted
0
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)
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
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:
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.