0

I've created table ip and created mapping files by wizards on NetBeans 8.2. Thats the ip schema: enter image description here

and added to hibernate config

<property name="connection.autocommit">true</property>

but when I'm trying to insert something to table query doesn't executes. On other tables it works.

    Session session = HibernateUtil.getSessionFactory().openSession();
    Ip info = new Ip();
    info.setAsn("aaaa");
    info.setCity("aaaa");
    info.setCountry("aa");
    info.setIp(213213);
    info.setIsp("aaaa");
    info.setLat(44.4);
    info.setLon(55.5);
    info.setOrg("aaaa");
    info.setRegion("aaaa");
    session.save(info);

2 Answers 2

1

you need to invoke session.flush().

Autocommit it's about pushing data to Database without invoking save method.

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

1 Comment

THANK YOU so much
0

In hibernate only the operation included in transacion will be sent to the database. so the correct code is:

 Session session = HibernateUtil.getSessionFactory().openSession();
 Ip info = new Ip();
info.setAsn("aaaa");
info.setCity("aaaa");
info.setCountry("aa");
info.setIp(213213);
info.setIsp("aaaa");
info.setLat(44.4);
info.setLon(55.5);
info.setOrg("aaaa");
info.setRegion("aaaa");
Transaction t = session.beginTransaction();
session.save(info);
t.commit();

Doing that hibernte will send the insert to database, it is not immediately (it is quite so) to be sure that it is sent immediately you have to flush the session with session.flush() but that is a plus hope this help r.

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.