//DataBaseTest database = new DataBaseTest();
Session session = SessionFactoryUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
DataPointConfig datapoint = null;
datapoint = new DataPointConfig();
datapoint.setName("datapoint1");
datapoint.setType("type1");
datapoint.setDataType("datatype1");
datapoint.setIsEquipmentPoint(true);
datapoint.setLocationId(1);
datapoint.setEquipmentId(2);
try
{
session.save(datapoint);
}
catch(ConstraintViolationException ex)
{
System.out.println("Constraint violation.");
//clear the session. otherwise, subsequent operation might fail
session.clear();
}
datapoint = new DataPointConfig();
datapoint.setName("datapoint2");
datapoint.setType("type2");
datapoint.setDataType("datatype2");
datapoint.setIsEquipmentPoint(false);
datapoint.setLocationId(1);
datapoint.setEquipmentId(2);
try
{
session.save(datapoint);
}
catch(ConstraintViolationException ex)
{
System.out.println("Constraint violation.");
//clear the session. otherwise, subsequent operation might fail
session.clear();
}
List<?> datapoints = null;
// //print out
// datapoints = session.createQuery("from DataPointConfig where name='datapoint1'").list();
// for (int i = 0; i < datapoints.size(); i++) {
// datapoint = (DataPointConfig) datapoints.get(i);
// System.out.println(
// "DataPoint: " + datapoint.getKeyId() + ", Name: " + datapoint.getName()
// );
//// //update it
//// datapoint.setName("datapoint3");
//// session.update(datapoint);
// }
System.out.println(
"----------------------------------------------");
//print out
datapoints = session.createQuery("from DataPointConfig").list();
for (int i = 0; i < datapoints.size(); i++) {
datapoint = (DataPointConfig) datapoints.get(i);
System.out.println(
"DataPoint: " + datapoint.getKeyId() + ", Name: " + datapoint.getName()
);
}
session.getTransaction().commit();
}