Question

I'm using Hibernate 4.3.5-Final for my Java Swing application and I do many UDPATE, INSERT and DELETE with it (in HQL or with Criteria).

Now, what I'm trying to do is to export a SQL script of all modifications done on my database but I don't know how to do that. This script need to contain only the modifications (and not the creation of the tables) and put them on a .sql file (exported file path will be chosen by the user)

Do you have any ideas that can solve my problem ?

Thank you in advance !

[Edit] : Some forums talk about p6spy, can it answer to my problem ?

Était-ce utile?

La solution

p6spy should help here.

In general, following should do the job for you:

  1. enable p6spy in your app (see official docs: http://p6spy.github.io/p6spy/)

afterwards you have basically 2 options:

  1. use provided: BatchFileLogger, enabling it via: appender=com.p6spy.engine.spy.appender.BatchFileLogger in spy.properties (it's however undocumented yet, see: https://github.com/p6spy/p6spy/issues/119)

OR

  1. implement custom com.p6spy.engine.spy.appender.MessageFormattingStrategy, that would be returning sql only (see: https://stackoverflow.com/a/23521623/1581069 for idea on implementation) and configure it in spy.properties via: logMessageFormat=FooFormat
  2. set sqlexpression to match the queries you need - restricting CREATE/ALTER/... TABLE/SEQUENCE/... (see official docs: http://p6spy.github.io/p6spy/2.0/configandusage.html)

still there are some tricky points, like:

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top