diff --git a/src/main/java/info/bukova/isspst/Constants.java b/src/main/java/info/bukova/isspst/Constants.java index 024e15f1..316a9b26 100644 --- a/src/main/java/info/bukova/isspst/Constants.java +++ b/src/main/java/info/bukova/isspst/Constants.java @@ -30,7 +30,7 @@ import java.util.Map; public class Constants { - public final static long DB_VERSION = 1; + public final static long DB_VERSION = 2; public final static String DEF_ADMIN = "admin"; public final static String DEF_ADMIN_PASSWD = "admin"; diff --git a/src/main/java/info/bukova/isspst/data/MUnitEmb.java b/src/main/java/info/bukova/isspst/data/MUnitEmb.java index 710ba805..934d54eb 100644 --- a/src/main/java/info/bukova/isspst/data/MUnitEmb.java +++ b/src/main/java/info/bukova/isspst/data/MUnitEmb.java @@ -20,6 +20,9 @@ public class MUnitEmb public MUnitEmb() { + // Embeddable object is loaded by hibernate like NULL, if all properties + // are NULL. So, we set ID. + this.id = 0; } public MUnitEmb(MUnit munit) diff --git a/src/main/java/info/bukova/isspst/services/dbinfo/DbInfoServiceImpl.java b/src/main/java/info/bukova/isspst/services/dbinfo/DbInfoServiceImpl.java index a859a28e..4203419a 100644 --- a/src/main/java/info/bukova/isspst/services/dbinfo/DbInfoServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/dbinfo/DbInfoServiceImpl.java @@ -64,9 +64,13 @@ public class DbInfoServiceImpl extends AbstractService implements DbInfo if (Constants.DB_VERSION > dbVersion) { + SQLQuery sq = null; + String sql = ""; + if (dbVersion < 1) { List tables = new ArrayList(); + tables.add(new Str2Str("address", "DESCRIPTION")); tables.add(new Str2Str("building", "DESCRIPTION")); tables.add(new Str2Str("material", "DESCRIPTION")); @@ -90,9 +94,6 @@ public class DbInfoServiceImpl extends AbstractService implements DbInfo tables.add(new Str2Str("triprequirement", "VEHICLE_DESCRIPTION")); tables.add(new Str2Str("trip_bill_items", "BACK_VEHICLE_DESCRIPTION")); tables.add(new Str2Str("trip_bill_items", "VEHICLE_DESCRIPTION")); - - SQLQuery sq = null; - String sql = ""; for (Str2Str item : tables) { @@ -102,6 +103,22 @@ public class DbInfoServiceImpl extends AbstractService implements DbInfo } } + if (dbVersion < 2) + { + List tables = new ArrayList(); + + tables.add("material"); + tables.add("order_item"); + tables.add("requirement_items"); + + for (String item : tables) + { + sql = "UPDATE " + item + " SET MUNIT_ID = 0 WHERE (MUNIT_ID Is NULL) "; + sq = this.dao.getSession().createSQLQuery(sql); + sq.executeUpdate(); + } + } + this.updateDatabaseVersion(); } } diff --git a/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java b/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java index cfb6409e..c3e96ec9 100644 --- a/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java +++ b/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java @@ -183,7 +183,14 @@ public class RequirementForm extends FormViewModel if (isMaterial) { Material materialItem = (Material) selected; - item.setMunit(materialItem.getMunit()); + MUnitEmb unit = materialItem.getMunit(); + + // if (unit == null) + // { + // unit = new MUnitEmb(); + // } + + item.setMunit(unit); } this.setSelectedItem(item);