I recently added new property in one class, its list property and I have written xml mapping for that property,due to few reasons I am not suppose to delete database or use create option in hibernate config file to update changes. I have to do it manual by executing sql queries on database.
xml mapping file:
<list name="items" table="ITEM_ITEM_GROUP" lazy="false" cascade="save-update">
<key column="ITEM_GROUP_ID"></key>
<list-index column="IG_INDEX" />
<many-to-many column="ITEM_ID" class="Item" />
</list>
can anyone please help how do i do it?
You are not just adding a column, you are adding a table.
The easiest approach is to use
SchemaExportto create an sql script of your database schema. Then you can copy-paste the new table with indexes and everything.In this case, you most probably don’t have to change an existing table, just add the new stuff.
In java, you can call SchemaExport directly from the command line. Take a look at a tutorial like this here.
In C# you need to write a utility which export the schema, code looks something like this:
It will basically be something like this (depending on your rdms you are using)
I probably missed something. So it’s best you let Hibernate create the schema and look into the generated SQL.