Results 1 to 7 of 7
  1. #1
    me.anchit is offline Member
    Join Date
    Jul 2011
    Posts
    26
    Rep Power
    0

    Post data not inserted in tables

    hi,
    I m new to using hibernate...
    this is the code i have written in servlet

    SessionFactory factory=new Configuration().configure().buildSessionFactory();
    Session ss=factory.openSession();
    Transaction tx=ss.beginTransaction();

    Userlogin userlogin=new Userlogin(username,password,"","","","","","",0);
    Userinfo userinfo=new Userinfo(email,userlogin,firstname,lastname,gender ,dob,occupation,registrationDate,registrationTime, registrationIp,0,0.0,0,0);
    ss.save(userlogin);
    ss.save(userinfo);
    tx.commit();
    if(tx.wasCommitted())
    {
    session.setAttribute("username",username);
    response.sendRedirect("home.jsp");
    }
    else
    {
    tx.rollback();
    response.sendRedirect("register.jsp");
    }
    ss.close();

    using this code, the data is not inserted in the two tables.
    plz help...
    thank u

  2. #2
    dinesh.guntha is offline Member
    Join Date
    May 2011
    Posts
    27
    Rep Power
    0

    Default Re: data not inserted in tables

    Above code is correctly but, were you configured your hibernate.cfg.xml file. it should be in the default folder

  3. #3
    me.anchit is offline Member
    Join Date
    Jul 2011
    Posts
    26
    Rep Power
    0

    Default Re: data not inserted in tables

    i have used netbeans, it must be correct..........

  4. #4
    me.anchit is offline Member
    Join Date
    Jul 2011
    Posts
    26
    Rep Power
    0

    Default Re: data not inserted in tables

    it is giving the following exception

    org.hibernate.exception.DataException: Could not execute JDBC batch update

    plz help
    thank u

  5. #5
    dinesh.guntha is offline Member
    Join Date
    May 2011
    Posts
    27
    Rep Power
    0

    Default Re: data not inserted in tables

    do you add the jdbc jar file and can you print the hibernate.cfg.xml file

  6. #6
    me.anchit is offline Member
    Join Date
    Jul 2011
    Posts
    26
    Rep Power
    0

    Default Re: data not inserted in tables

    yes the jar file is added in the library.
    If I remove the line ss.save(userinfo), it is able to insert data in userlogin table.....
    but i want data to be inserted in both the tables...
    what to do...???
    :(

  7. #7
    dinesh.guntha is offline Member
    Join Date
    May 2011
    Posts
    27
    Rep Power
    0

    Default Re: data not inserted in tables

    In hibernate,

    Userlogin userlogin=new Userlogin(username,password,"","","","","","",0);
    Userinfo userinfo=new Userinfo(email,userlogin,firstname,lastname,gender ,dob,occupation,registrationDate,registrationTime, registrationIp,0,0.0,0,0);
    //ss.save(userlogin);
    ss.save(userinfo);

    it will automatically take data abd store in db. that is one of the adv in hibernate.
    In userinfo obj you storing the userlogin obj details.
    if any prb plz print the hibernate.cfg.xml file their you should specify the relation ship

Similar Threads

  1. Data not inserted into an object
    By LoViNgHeArTy in forum New To Java
    Replies: 11
    Last Post: 06-28-2011, 05:51 AM
  2. how to format data tables
    By tlyn in forum New To Java
    Replies: 2
    Last Post: 04-19-2011, 07:11 PM
  3. how to get data from more than two tables based on other
    By kishan.java in forum New To Java
    Replies: 1
    Last Post: 03-24-2011, 12:20 PM
  4. Replies: 1
    Last Post: 01-31-2011, 02:38 AM
  5. How to use one form to submit data to 2 tables on mysql
    By kwesiaryee in forum New To Java
    Replies: 2
    Last Post: 10-10-2008, 01:41 PM

Tags for this Thread

Posting Permissions

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