AnyLogic Initialization Order: Java and Database
Product Mixer property → ModelConstants → database
The problem is therefore not the database value itself, but the timing of its initialization. A common workaround is to perform a null check before accessing ModelConstants:if (modelConstants == null) {
initializeModelConstants();
}
return modelConstants.getValue(...); Agent initialization → property evaluation → ModelConstants → database
to:Experiment initialization → ModelConstants → database → agent initialization → property evaluation
This approach keeps database initialization separate from individual components and makes the overall model architecture more predictable and maintainable.try (Connection conn = DriverManager.getConnection(url, "sa", "");
PreparedStatement stmt = conn.prepareStatement(SQL_QUERY);
ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
add(
rs.getString("constant_label"),
rs.getString("constant_name"),
rs.getString("description"),
rs.getDouble("constant_value"),
rs.getString("constant_unit")
);
}
} public ModelConstants() {
this(new java.io.File(".").getAbsolutePath());
}