Results 1 to 2 of 2
  1. #1
    Saritha is offline Member
    Join Date
    Jun 2007
    Posts
    1
    Rep Power
    0

    Default Friends could u plz give me solution 4 this

    Using hibernate i am just trying to insert a record ..... but i thowing exception

    Hibernate: select max(id) from check
    Exception in thread "main" org.hibernate.TransactionException: Transaction not successfully started
    at org.hibernate.transaction.JDBCTransaction.commit(J DBCTransaction.java:100)
    at Test.main(Test.java:18)

    This is my code .....

    Session s = HibernateUtil.currentSession();
    Check c = new Check();
    c.setName("Sankya-p");
    c.setAddress("Isro-p");
    Transaction t = s.getTransaction();
    s.save(c);
    t.commit();
    HibernateUtil.closeSession();

    and hbm file ....
    <class name="Check" table="check">
    <id
    name="id"
    type="integer"
    column="id"
    >
    <generator class="increment"/>
    </id>

    <property
    name="name"
    type="string"
    column="name"
    length="20"
    />
    <property
    name="address"
    type="string"
    column="address"
    length="20"
    />
    </class>

  2. #2
    Peter is offline Senior Member
    Join Date
    Jun 2007
    Posts
    119
    Rep Power
    0

    Default

    This error appears because you didn't do a begin transaction, and tried to do a commit of it
    You didn't do this line t.beginTransaction();
    example:
    Java Code:
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();
            try {
                SQLQuery query = session.createSQLQuery("select name from condition");
                System.out.println(query.list().get(0).toString());
            } 
            catch (Exception ex) {
                ex.printStackTrace();
            }  
    session.close();
    Last edited by Peter; 06-16-2007 at 05:51 PM.

Similar Threads

  1. anyone can give idea 2 my assignment?
    By chen8735 in forum Advanced Java
    Replies: 2
    Last Post: 03-08-2008, 07:03 PM
  2. Replies: 0
    Last Post: 01-19-2008, 10:04 AM
  3. Give me some suggestion on wedding story book
    By roots in forum Forum Lobby
    Replies: 1
    Last Post: 01-10-2008, 05:17 PM
  4. Simple serverless chat solution
    By goodjonx in forum Networking
    Replies: 3
    Last Post: 01-07-2008, 04:25 PM
  5. give me a advise
    By sireesha in forum New To Java
    Replies: 3
    Last Post: 12-11-2007, 02:38 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
  •