1

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

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks for your answer but my update is not update in my db. thanks
no sorry, i haven't error but its no updating in db
you can try int results=qry.executeUpdate() and printing "results" and chek value is it really updating or not. If its 1 that means code is updating but not recording in your database. If its 0, that means no problem with ur db, its your query
I tested, result is equals to "1"
then your problem is might with commiting, try session.commit() instead of tx.commit();
|
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.