INSERT LOW_PRIORITY or INSERT DELAYED in sleep mode

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

In my logging program, I want to insert log information into a table in my database for further analysis. But I don't care how long it takes to insert, so normally I would say INSERT LOW_PRIORITY INTO LogEntry (level, header, full) VALUES ("Info", "Title here", "Full log"); If I have a LogEntry object, how do I write or wire my LogEntryDAO to make attachments and updates LOW_PRIORITY or DELAYED?

Greetings

Nick

+2


source to share


3 answers


There is a much simpler solution.

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



Nice and elegant :-)

+2


source


Use org.hibernate.Interceptor

. It will get a copy of the SQL to execute for modification.



See the docs for details .

+2


source


I would say that the best solution would be for the Log4J application to write this message to the queue and the MessageListener to pick it up and insert it into the database.

Your application is decoupled from the database this way, and you don't care how long it takes. If your database goes down, your persistent queue can accumulate messages until you can get them back.

Be sure to use the XA JDBC driver and transaction manager so that the queue and database can be the same transaction.

+1


source







All Articles