Force Hibernate Insert Without Select Statements

前端 未结 3 1060
孤城傲影
孤城傲影 2020-12-06 17:44

I am attempting to insert a new record into a table that I know is unique before hand. I have tried calling save() on the object, but that does a bunch of SELECT statements

3条回答
  •  难免孤独
    2020-12-06 18:39

    Hibernate doesn't issue a select to see if an object is unique upon a save(). In point of fact, Hibernate doesn't even issue an insert when you call save(). That happens when you flush() or commit the transaction. You'll need to find out exactly what the selects are for and what's initiating them. To help narrow it down, you could write a quick test like

    Session session = openSession();
    Transaction tx = session.beginTransaction();
    session.save(myObject);
    tx.commit();
    

    and see what statements that produces.

提交回复
热议问题