I'm trying to insert a record in DB using Hibernate. The data gets saved in to multiple tables in the DB. On the hibernate side I have a parent Entity class with one-to-one and one-to-many mapping to other Entity classes. In debug mode, I could see that the save operation results in multiple sql inserts. The first insert sql takes a long time, approximately 300 milliseconds. Please note: This does not include time taken for Session Initialisation, Obtaining JDBC connection etc. 10:46:24.132 [main] DEBUG org.hibernate.SQL - insert into MY_SCHEMA_NAME.PARENT_ENTITY (COLUMN1, COLUMN2, COLUMN3, COLUMN4, COLUMN5, COLUMN6, COLUMN7, COLUMN8, COLUMN9, COLUMN10, COLUMN11, COLUMN12, COLUMN13, COLUMN14) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
The same sql if I execute from any other tool ( Oracle SQL developer ) it takes about 20 milliseconds.
The subsequent sql inserts executed by hibernate takes only about 15-20 milliseconds.
The question is, why the fist sql insert in Hibernate takes so much time, nearly 10 times when compared to subsequent sql inserts?