Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

INSERT LOW_PRIORITY or INSERT DELAYED in Hibernate

How do I do a low_priority or delayed insert into a MySQL table with Hibernate?

In my logging routine I want to insert the log info to a table in my database for further analysis. But I don't care about how long it takes for the insert to be done, so usually I would say INSERT LOW_PRIORITY INTO LogEntry (level, title, full) VALUES ('Info', 'Title here', 'Full log'); If I have an entity LogEntry, how do I write or wire up my LogEntryDAO to do LOW_PRIORITY or DELAYED inserts and updates?

Cheers

Nik

like image 250
niklassaers Avatar asked Jun 27 '26 01:06

niklassaers


2 Answers

There is a much simpler solution.

Annotate my entity class with @SQLInsert(sql="INSERT LOW_PRIORITY INTO LogEntry (level, title, full) VALUES (?, ?,?)")

Nice and elegant :-)

like image 132
niklassaers Avatar answered Jun 29 '26 13:06

niklassaers


Use an org.hibernate.Interceptor. It will get a copy of the SQL to execute to modify.

See the docs for details.

like image 37
Aaron Digulla Avatar answered Jun 29 '26 13:06

Aaron Digulla



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!