The ID column is a autoIncrement and the value which is used for this ID should be used in another insert statement. Is there any “Liquibase way” of getting this value? If so - how?
An alternative approach is to use a custom SQL which fetches the value. Since I use MySQL, I can use the LAST_INSERT_ID() function to fetch this value, but how do I put this value into a variable that Liquibase can utilize?
There currently isn’t an official way, unfortunately.
There is always the tag to fall back on for sql that the standard tags do not support, and with 2.0 you can write a liquibase extension (liqubase.org/extensions) to allow you to modify the SQL generated by the standard change tags and add additional attributes to fit what you want to do as well.
What is the tag you want to use the LAST_INSERT_ID in?
In a webapp I use Hibernate as an JPA1.0 provider and liquibase is used via the ServletListener.
My EntityClass has an @GeneratedValue annotation, yet I need to insert some initial data. In Derby, Hibernate uses a table in order to generate the values for primary keys. So I can’t simply choose an arbitrary value as a primary key, even in an empty database as this would confuse Hibernate, as sooner or later Hibernate could try to use the same PK on the same table.
It would be very handy if one could simply do something like
Or ist it something I am missing? Is there a way to use JPA as a datasource for the Servlet Listener without a dedicated hibernate configuration file? I don’t need it with JPA, so maintaining it for the sole purpose of using liquibase seems a bit… …unsatisfying.
It is technically possible to have liquibase pull the hibernate config from the JPA configuraiton, but I haven’t had the time to get it into the codebase yet, unfortunately. Feel free to look at the source if you or anyone else would like to add support.