/** * Updating an environment * * @param pkEenvironment primary key of the environment * @param description description of the environment * @param environment value of the environment */ public void updateEnvironment(Long pkEnvironment, String description, String environment) { sessionFactory = HibernateUtil.configureSessionFactory(); session = sessionFactory.openSession(); tx = session.beginTransaction(); query = session.createQuery("from Environment e where e.pkEnvironment =" + pkEnvironment); Environment env = (Environment) query.uniqueResult(); env.setDescription(description); env.setEnvironmentName(environment); session.persist(env); tx.commit(); session.close(); }
/** * Creating a new environment * * @param description description of the environment * @param environment value of the environment * @param envAttr list of environment attributes */ public void createEnvironment( String description, String environment, List<EnvironmentAttribute> envAttr) { sessionFactory = HibernateUtil.configureSessionFactory(); session = sessionFactory.openSession(); tx = session.beginTransaction(); Environment env = new Environment(environment, description); env.setEnvironmentAttributes(new HashSet<EnvironmentAttribute>(envAttr)); session.persist(env); for (EnvironmentAttribute attr : envAttr) { attr.setEnvironment(env); session.persist(attr); for (EnvAttrValues val : attr.getEnvAttrValues()) { val.setEnvironmentAttribute(attr); session.persist(val); } } tx.commit(); session.close(); }