Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-02-2008, 01:11 AM
Member
 
Join Date: Nov 2007
Posts: 45
sireesha is on a distinguished road
Problem with First Hibernate program
Hi EveryOne,

I downloaded hibernate-3.2.6 and i working with eclipse3.3,oracle10g and JRE 1.6.
Is it necessary to download any plugins for hibernate to use in eclipse ?
I wrote a simple java application using hibernate.To write that code i took some help from a website.Here is my directory structure...


HibernatePro1
l
l__src
l l
l l_ events
l l l_ Event.java
l l l
l l l_ Event.hbm.xml
l l
l l_ client
l l l_ TestClient.java
l l l
l l l_ EventManager.java
l l
l l__Event.cfg.xml
l l
l l
l l__log4j.properties
l
l
l__+JRE System Library
l
l__+Hibernate User Library


I included all my hibernate .jar files in "Hibernate User Library"

Now when i try to run TestClient.java i am getting exception like below
Code:
17:12:05,062 INFO Environment:514 - Hibernate 3.2.6 17:12:05,093 INFO Environment:547 - hibernate.properties not found 17:12:05,156 INFO Environment:681 - Bytecode provider name : cglib 17:12:05,171 INFO Environment:598 - using JDK 1.4 java.sql.Timestamp handling 17:12:05,390 INFO Configuration:1432 - configuring from resource: /hibernate.cfg.xml 17:12:05,390 INFO Configuration:1409 - Configuration resource: /hibernate.cfg.xml Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml not found at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:147) at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1411) at org.hibernate.cfg.Configuration.configure(Configuration.java:1433) at org.hibernate.cfg.Configuration.configure(Configuration.java:1420) at client.TestClient.openSession(TestClient.java:23) at client.TestClient.main(TestClient.java:48)
Is there any wrong with my directory structure ?
Can any one please help me in solving this problem.

Thank q very much,
sirisha.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-02-2008, 08:28 AM
danielstoner's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Canada
Posts: 183
danielstoner is on a distinguished road
You have to place a hibernate.cfg.xml configuration file in your source directory. That files configures how Hibernate works. It includes references to the *.hbm.xml files. You don't need any special plugin but you can find one to help you.
__________________
Daniel @ [
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
]
Language is froth on the surface of thought
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-02-2008, 05:04 PM
Member
 
Join Date: Nov 2007
Posts: 45
sireesha is on a distinguished road
Thanks for your reply,
But i have one doubt.I think, in my example src is the source directory.So i placed it there.Even though i am getting that exception.
Can u please tell me,what is source directory in my structure.

Thank q very much,
sirisha.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-03-2008, 12:06 AM
danielstoner's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Canada
Posts: 183
danielstoner is on a distinguished road
The hibernate.cfg.xml file should be placed in the source folder along with the log4j.properties file. If you are working with Eclipse these files should be copied in the classes (bin) folder where the result of the compilation goes. It looks like your suource folder is "src". If this doesn't work just copy the files by hand into the classes folder.
__________________
Daniel @ [
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
]
Language is froth on the surface of thought
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-03-2008, 04:06 PM
Member
 
Join Date: Nov 2007
Posts: 45
sireesha is on a distinguished road
Thank q very much danielstoner,
I am working with eclipse.Even though i have copies of hibernate.cfg.xml file and log4j.properties file in my build directory,I am getting that Exception.
I am really stuck with this problem.Because of this i couldn't go to learn other topics in hibernate.
Can u please tell me any other ways to solve this problem.
Thank q very much.
sireesha.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-04-2008, 06:54 AM
Member
 
Join Date: Nov 2007
Posts: 45
sireesha is on a distinguished road
Hi,
I solved this problem by adding hibernate.properties file to my src folder and by changing names of Event.cfg.xml and Event.hbm.xml to hibernate.cfg.xml and hibernate.hbm.xml.Now it's working fine now.

But now i have some problem with logic of my code.I am placing my client programs here please check these once.
Code:
package client; import org.hibernate.*; import org.hibernate.cfg.Configuration; import events.*; public class TestClient { public Event buildEvent() { Event event = new Event(); event.setEventTitle("Environmental Meet"); event.setTotalMembers(100); return event; } public Session openSession() { SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); Session session =sessionFactory.openSession(); return session; } public Event testSaveEvent(EventManager manager) { Event event = buildEvent(); manager.saveEvent(event); System.out.println("Event saved with ID = "+event.getEventId()); return event; } public static void main(String[] args) { TestClient client = new TestClient(); Session session = client.openSession(); EventManager manager = new EventManager(session); Event event = client.testSaveEvent(manager); System.out.println("End of Program"); session.flush(); } }
and
Code:
package client; import org.hibernate.Session; import events.Event; public class EventManager { private Session session = null; public EventManager(Session session) { if(session == null) throw new RuntimeException("Invalid session object. Cannot instantiate the EventManager."); this.session = session; } public void saveEvent(Event event) { session.save(event); } }
Now my problem is...
1. when i try to save a row by using these classes,all those previous values(entered from Oracle) are getting deleted.Now my table is having only one row which is entered through this classes.
2. After this i changed entry values for that table fields in my class and now i run this client program once again.Now my previously entered row in step1 was deleted and now my table contains new row only.
At any time i am getting only one row in my table.But i want to save all those rows in my table.

What is wrong with my code.Can any one please help me..

Thank q very much,
sireesha.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 05-04-2008, 10:17 AM
Member
 
Join Date: May 2008
Posts: 2
sarava20 is on a distinguished road
Problem with First Hibernate program
Hi Sireesha,

i guess this cud be a prob,

Comment the following tag in *.cfg.xml(hibernate.cfg.xml)

<!-- Drop and re-create the database schema on startup
<property name="hbm2ddl.auto">create</property>
-->
while u execute ur program , Create means each and every time all the tables are dropped and re create again...so just comment while u execute ur application second time onwards.

Thanks
Saravanan
Mindtree-Chennai
sarava20@gmail.com
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 05-04-2008, 04:30 PM
Member
 
Join Date: Nov 2007
Posts: 45
sireesha is on a distinguished road
Thanks Saravanan,
I removed that tag from hibernate.cfg.xml ,Now it's working fine.
Thank very much,
sireesha.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 05-05-2008, 09:20 AM
danielstoner's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Canada
Posts: 183
danielstoner is on a distinguished road
Sireesha, if the thread is solved mark it so please.
__________________
Daniel @ [
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
]
Language is froth on the surface of thought
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 05-05-2008, 02:30 PM
Member
 
Join Date: Nov 2007
Posts: 45
sireesha is on a distinguished road
Hi Daniel,
Thank q very much,I will do it from the next time.
Thanks,
sirisha.
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 05-05-2008, 03:02 PM
Moderator
 
Join Date: Nov 2007
Posts: 1,415
Java Tip will become famous soon enoughJava Tip will become famous soon enough
Quote:
Thank q very much,I will do it from the next time.
You can still do it!
__________________
Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 05-05-2008, 05:19 PM
Member
 
Join Date: Nov 2007
Posts: 45
sireesha is on a distinguished road
Sorry,
I searched for that option,but i couldn't find out how to do that..
Can u please tell me.
Thanks,
sireesha.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with my first Struts program....please help me sireesha Web Frameworks 4 04-04-2008 07:33 AM
composite-id problem hibernate javadev Database 13 01-28-2008 09:12 AM
problem with hibernate and oracle 8i javadev Database 4 08-09-2007 03:21 PM
Problem with my program HelloWorld trill New To Java 1 08-05-2007 06:32 PM
Log4J, problem with Hibernate and Spring Marcus Advanced Java 1 06-06-2007 04:22 AM


All times are GMT +3. The time now is 02:59 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org