Package org.hibernate

Examples of org.hibernate.Session.saveOrUpdate()


     */
    public static void addGroup(Group group) {
        Session session = getSessionFactory().getCurrentSession();
       
        session.beginTransaction();
        session.saveOrUpdate(group);
        session.getTransaction().commit();
    }

    /**
     * Adds an article to Group g and updates the links Group - Article.
View Full Code Here


       
        session.beginTransaction();
        g = (Group) session.createQuery("from Group where id=" + g.getId()).uniqueResult();
        g.getArticles().add(article);
        article.getGroups().add(g);
        session.saveOrUpdate(article);
        session.saveOrUpdate(g);
        session.getTransaction().commit();
    }

    public static Group getGroup(String groupname) {
View Full Code Here

        session.beginTransaction();
        g = (Group) session.createQuery("from Group where id=" + g.getId()).uniqueResult();
        g.getArticles().add(article);
        article.getGroups().add(g);
        session.saveOrUpdate(article);
        session.saveOrUpdate(g);
        session.getTransaction().commit();
    }

    public static Group getGroup(String groupname) {
        Session session = getSessionFactory().getCurrentSession();
View Full Code Here

        Iterator<Article> it = group.getArticles().iterator();
        Article a;
        while(it.hasNext()) {
            a = it.next();
            a.setRead(read);
            session.saveOrUpdate(a);
        }
        session.getTransaction().commit();
    }

    /**
 
View Full Code Here

    public static void subscribe(Group group, boolean subscribed) {
        Session session = getSessionFactory().getCurrentSession();
       
        session.beginTransaction();
        group.setSubscribed(subscribed);
        session.saveOrUpdate(group);
        session.getTransaction().commit();
    }

    /**
     * Removes Article <code>a</code> from database.
View Full Code Here

        Iterator<Group> it = a.getGroups().iterator();
        Group g;
        while(it.hasNext()) {
            g = it.next();
            g.getArticles().remove(a);
            session.saveOrUpdate(g);
        }
        session.delete(a);
        session.getTransaction().commit();
    }
View Full Code Here

    public static void markRead(Article a, boolean read) {
        Session session = getSessionFactory().getCurrentSession();
       
        session.beginTransaction();
        a.setRead(read);
        session.saveOrUpdate(a);
        session.getTransaction().commit();
    }

}
View Full Code Here

  }
 
  void save(Object a) {
    Session s = sessionFactory.openSession();
    s.beginTransaction();
    s.saveOrUpdate(a);
    s.getTransaction().commit();
    s.close();
  }
   
 
View Full Code Here

                planet.setSatellites(new HashSet<Satellite>());
                planet.getSatellites().addAll(satellites);

            }

            session.saveOrUpdate(planet);

            // session.flush();
            // session.close();
        } catch (Exception e) {
View Full Code Here

                planet.setSatellites(new HashSet<Satellite>());
                planet.getSatellites().addAll(satellites);

            }

            session.saveOrUpdate(planet);

            // session.flush();
            // session.close();
        } catch (Exception e) {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.