Results 1 to 12 of 12
  1. #1
    sireesha is offline Member
    Join Date
    Nov 2007
    Posts
    50
    Rep Power
    0

    Question 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
    Java 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 
    [COLOR="Red"]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) 
    [/COLOR]
    Is there any wrong with my directory structure ?
    Can any one please help me in solving this problem.

    Thank q very much,
    sirisha.

  2. #2
    danielstoner's Avatar
    danielstoner is offline Senior Member
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    191
    Rep Power
    7

    Default

    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 @ [www.littletutorials.com]
    Language is froth on the surface of thought

  3. #3
    sireesha is offline Member
    Join Date
    Nov 2007
    Posts
    50
    Rep Power
    0

    Default

    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.

  4. #4
    danielstoner's Avatar
    danielstoner is offline Senior Member
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    191
    Rep Power
    7

    Default

    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 @ [www.littletutorials.com]
    Language is froth on the surface of thought

  5. #5
    sireesha is offline Member
    Join Date
    Nov 2007
    Posts
    50
    Rep Power
    0

    Default

    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.

  6. #6
    sireesha is offline Member
    Join Date
    Nov 2007
    Posts
    50
    Rep Power
    0

    Default

    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.
    Java Code:
    package client;
    import org.hibernate.*;
    import org.hibernate.cfg.Configuration;
    import events.*;
    
    public class TestClient
    {
    [COLOR="Blue"]public Event buildEvent()
    {
     Event event = new Event();
    
     event.setEventTitle("Environmental Meet");
     event.setTotalMembers(100);
     return event;
    }[/COLOR]
    public Session openSession()
    {
      SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
      Session session =sessionFactory.openSession();
      return session;
    }
    [COLOR="Blue"]public Event testSaveEvent(EventManager manager) 
    {
      Event event = buildEvent();
      manager.saveEvent(event);
      System.out.println("Event saved with ID = "+event.getEventId());
      return event;
    }[/COLOR]
    public static void main(String[] args) 
    {
      TestClient client = new TestClient();
     Session session = client.openSession();
      EventManager manager = new EventManager(session);
     [COLOR="Blue"] Event event = client.testSaveEvent(manager);[/COLOR]
      System.out.println("End of Program");
      session.flush();
    }
    }
    and
    Java 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.

  7. #7
    sarava20 is offline Member
    Join Date
    May 2008
    Posts
    2
    Rep Power
    0

    Default 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

  8. #8
    sireesha is offline Member
    Join Date
    Nov 2007
    Posts
    50
    Rep Power
    0

    Default

    Thanks Saravanan,
    I removed that tag from hibernate.cfg.xml ,Now it's working fine.
    Thank very much,
    sireesha.

  9. #9
    danielstoner's Avatar
    danielstoner is offline Senior Member
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    191
    Rep Power
    7

    Default

    Sireesha, if the thread is solved mark it so please.
    Daniel @ [www.littletutorials.com]
    Language is froth on the surface of thought

  10. #10
    sireesha is offline Member
    Join Date
    Nov 2007
    Posts
    50
    Rep Power
    0

    Default

    Hi Daniel,
    Thank q very much,I will do it from the next time.
    Thanks,
    sirisha.

  11. #11
    Java Tip's Avatar
    Java Tip is offline Moderator
    Join Date
    Nov 2007
    Posts
    1,694
    Blog Entries
    430
    Rep Power
    10

    Default

    Thank q very much,I will do it from the next time.
    You can still do it!

  12. #12
    sireesha is offline Member
    Join Date
    Nov 2007
    Posts
    50
    Rep Power
    0

    Default

    Sorry,
    I searched for that option,but i couldn't find out how to do that..
    Can u please tell me.
    Thanks,
    sireesha.

Similar Threads

  1. Problem with my first Struts program....please help me
    By sireesha in forum Web Frameworks
    Replies: 5
    Last Post: 10-16-2011, 05:19 PM
  2. composite-id problem hibernate
    By javadev in forum JDBC
    Replies: 14
    Last Post: 07-27-2009, 07:30 PM
  3. problem with hibernate and oracle 8i
    By javadev in forum JDBC
    Replies: 4
    Last Post: 08-09-2007, 03:21 PM
  4. Problem with my program HelloWorld
    By trill in forum New To Java
    Replies: 1
    Last Post: 08-05-2007, 06:32 PM
  5. Log4J, problem with Hibernate and Spring
    By Marcus in forum Advanced Java
    Replies: 1
    Last Post: 06-06-2007, 04:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •