Results 1 to 17 of 17
Thread: Hibernate
- 04-17-2011, 11:41 AM #1
Member
- Join Date
- Apr 2011
- Posts
- 9
- Rep Power
- 0
Hibernate
I need to use Hibernate for my connection to a database. I tried to use it with eclipse but I get some error messages that the import "org.hibernate" can't be resolved. I included the following jar's:
antlr-2.7.6.jar
cglib-2.2.jar
commons-collections-3.1.jar
dom4j-1.6.1.jar
hibernate3.jar
hibernate-jpa-2.0-api-1.0.0.Final.jar
javassist-3.12.0.GA.jar
jta-1.1.jar
slf4j-api-1.6.1.jar
Does anybody know what I need to do?
- 04-17-2011, 12:42 PM #2
I guess you don't add this library in class-patch in Eclipse.
Skype: petrarsentev
http://TrackStudio.com
- 04-17-2011, 02:01 PM #3
What do you mean about "build path"?
By the way in this case very useful to use maven. You just create projects for Hibernate and It downloads needs libraries itself.Last edited by Petr; 04-17-2011 at 02:03 PM.
Skype: petrarsentev
http://TrackStudio.com
- 04-17-2011, 04:01 PM #4
Member
- Join Date
- Apr 2011
- Posts
- 9
- Rep Power
- 0
Ok I fixed the problem with the jar-Files, but know I always get an error when I try to create a new session with the configuration xml-File. I'm not that into xml so I don't really know where my problem is...
Java Code:package com.sample; import java.util.List; import java.util.Iterator; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import com.sample.HibernateUtil; public class Test { public static void main(String[] args) { SessionFactory session = HibernateUtil.getSessionFactory(); } }I put the hibernate.cfg.xml file in the same folder where the .java files areJava Code:package com.sample; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; public class HibernateUtil { private static SessionFactory sessionFactory = null; public static SessionFactory getSessionFactory() { if (sessionFactory == null) { try { sessionFactory = new Configuration().configure().buildSessionFactory(); } catch (Throwable ex) { System.err.println("Initial sessionFactory creation failed\n" + ex); System.exit(1); } } return sessionFactory; } }
Here the code:
But I always jump in the catch-clause in the HibernateUtil.java...Java Code:<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <!-- a SessionFactory instance listed as /jndi/name --> <session-factory name="java:hibernate/SessionFactory"> <!-- properties --> <property name="dialect">org.hibernate.dialect.DB2Dialect</property> <property name="hibernate.connection.driver_class">com.ibm.db2.jcc.DB2Driver</property> <property name="hibernate.connection.password">*****</property> <property name="hibernate.connection.url">*****</property> <property name="hibernate.connection.username">****</property> </session-factory> </hibernate-configuration>
- 04-17-2011, 04:19 PM #5
The hibernate.hbm.xml is located in root src or you must point full path where it is located.
src/hibernate.hbm.xml
src/com/sample/HibernateUtil.javaSkype: petrarsentev
http://TrackStudio.com
- 04-17-2011, 04:27 PM #6
Member
- Join Date
- Apr 2011
- Posts
- 9
- Rep Power
- 0
I'm sorry but where do I have to edit that?
- 04-17-2011, 04:32 PM #7
There are around way either move your configuration in root folder src or point full path look like
Java Code:SessionFactory sf = new Configuration().configure("./pachage/../catdb.cfg.xml").buildSessionFactory();Skype: petrarsentev
http://TrackStudio.com
- 04-18-2011, 09:53 AM #8
Member
- Join Date
- Apr 2011
- Posts
- 9
- Rep Power
- 0
I tried both but neither worked, still get the error:
Java Code:Initial sessionFactory creation failed java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
- 04-18-2011, 09:55 AM #9
That is OK. you forgot to point logger in class-path. So I think it is bad idea to debug your code through this forum, I should read a book about Hibernate for example Hibernate in action. It is a very useful book.
I hope it helps.Skype: petrarsentev
http://TrackStudio.com
- 04-18-2011, 10:18 AM #10
Member
- Join Date
- Apr 2011
- Posts
- 9
- Rep Power
- 0
I forgot to add the commons-logging-1.1.1.jar in the build path, did it know but still get the same error message, also tried to clean the project and to add the whole .jar Files again but did't work...
- 04-18-2011, 10:22 AM #11
- 04-18-2011, 11:29 AM #12
Member
- Join Date
- Apr 2011
- Posts
- 9
- Rep Power
- 0
Google....
- 04-18-2011, 11:42 AM #13
Member
- Join Date
- Apr 2011
- Posts
- 9
- Rep Power
- 0
Was able to fix the problem but now I got an other one:
Java Code:Apr 18, 2011 12:57:45 PM org.hibernate.cfg.Environment <clinit> INFO: Hibernate 3.2.1 Initial sessionFactory creation failed java.lang.ExceptionInInitializerError
- 04-18-2011, 11:58 AM #14
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Is that the full stack trace?
Also, this trial and error is not really required since there are manuals that tell all the things you need to do get hibernate working.
- 04-18-2011, 12:07 PM #15
Member
- Join Date
- Apr 2011
- Posts
- 9
- Rep Power
- 0
Here the whole stack trace:
Java Code:Apr 18, 2011 1:22:40 PM org.hibernate.cfg.Environment <clinit> INFO: Hibernate 3.2.1 java.lang.ExceptionInInitializerError at org.hibernate.cfg.Configuration.reset(Configuration.java:168) at org.hibernate.cfg.Configuration.<init>(Configuration.java:187) at org.hibernate.cfg.Configuration.<init>(Configuration.java:191) at com.sample.HibernateUtil.getSessionFactory(HibernateUtil.java:13) at com.sample.Test.main(Test.java:110) Caused by: java.lang.NullPointerException at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:144) at org.hibernate.cfg.Environment.<clinit>(Environment.java:515) ... 5 more
- 04-18-2011, 12:29 PM #16
Can you show snippet a ConfigHelper.java:144?
So can you tell what aim you will get?
I mean it is commercial projects or you just education task.
I ask about it because you have bad approach in studying.Skype: petrarsentev
http://TrackStudio.com
- 04-19-2011, 05:58 AM #17
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Similar Threads
-
Should I be using hibernate?
By sephiroth2212 in forum JDBCReplies: 3Last Post: 04-03-2011, 10:24 AM -
Hibernate Use
By sireesha in forum JDBCReplies: 2Last Post: 05-21-2008, 03:05 AM -
Hibernate DAO
By sundarjothi in forum EclipseReplies: 0Last Post: 04-26-2008, 08:29 AM -
hibernate
By vipinpvijayan in forum Web FrameworksReplies: 1Last Post: 04-21-2008, 05:41 PM -
org.hibernate.ejb.Version <clinit> INFO: Hibernate EntityManager 3.2.0.CR1
By Heather in forum JDBCReplies: 2Last Post: 06-30-2007, 03:01 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks