Biohazard401
Biohazard401

Reputation: 41

Update query executing but not updating table with hibernate

I have a db with 5 pieces (id, question, result) and i want to change my db with update query and hibernate.

I tried this

public void update()
    {
        try
        {
            Session session = getSession();
            Transaction tx = session.beginTransaction();                

            Query query = getSession().createQuery("update Nodes set question = 'test updating' where id = 1" );

            tx.commit();
            session.close();

I don't have error, in console i have

Infos: Hibernate: update node set question='test updating' where id=1

Hibernate execute my update without error but there is not in my db, why ?

Thanks

Upvotes: 1

Views: 2878

Answers (2)

Charvee Shah
Charvee Shah

Reputation: 720

Try this.

    public void update()
    {
        try
        {
            Session session = getSession();
            Transaction tx = session.beginTransaction();                

            Query query = session.createQuery("update Nodes set question = 'test updating' where id = 1" );

            query.executeUpdate(); //add this line
            tx.commit();
            session.close();
    }

}

Hope this will help you.

Upvotes: 0

ajitksharma
ajitksharma

Reputation: 2019

Try this

public void update()
{
    try
    {
        Session session = getSession();
        Transaction tx = session.beginTransaction();                

        Query query = getSession().createQuery("update Nodes set question = 'test updating' where id = 1" );

        query.executeUpdate(); //add this line
        session.commit();
        session.close();

hope this helps you with your problem

Upvotes: 1

Related Questions