Example usage for org.hibernate Hibernate initialize

List of usage examples for org.hibernate Hibernate initialize

Introduction

In this page you can find the example usage for org.hibernate Hibernate initialize.

Prototype

public static void initialize(Object proxy) throws HibernateException 

Source Link

Document

Force initialization of a proxy or persistent collection.

Usage

From source file:com.pkrete.locationservice.endpoint.dao.locations.LocationsDao.java

License:Open Source License

/**
 * Returns all the libraries which id is in the given list. All the lazy
 * relationships are loaded. If children is true, all the collections and
 * shelves belonging to the libraries are loaded too.
 *
 * @param ids list of ids//from w w w  .java 2s.  co  m
 * @param children if true, all the collections and shelves belonging to the
 * libraries are loaded
 * @return libraries matching the given ids
 */
@Override
public List<Library> getLibraries(List<Integer> ids, boolean children) {
    List<Library> result = (List<Library>) getHibernateTemplate()
            .findByNamedParam("select distinct lib from Library as lib " + "left join fetch lib.image "
                    + "left join fetch lib.map " + "left join fetch lib.areas "
                    + "where lib.locationId in (:ids) ", "ids", ids);
    for (Library lib : result) {
        Hibernate.initialize(lib.getNotes());
        Hibernate.initialize(lib.getDescriptions());
        if (children) {
            for (LibraryCollection col : lib.getCollections()) {
                Hibernate.initialize(col.getNotes());
                Hibernate.initialize(col.getDescriptions());
                Hibernate.initialize(col.getSubjectMatters());
                Hibernate.initialize(col.getAreas());
                Hibernate.initialize(col.getImage());
                Hibernate.initialize(col.getMap());
                for (Shelf shelf : col.getShelves()) {
                    Hibernate.initialize(shelf.getNotes());
                    Hibernate.initialize(shelf.getDescriptions());
                    Hibernate.initialize(shelf.getSubjectMatters());
                    Hibernate.initialize(shelf.getAreas());
                    Hibernate.initialize(shelf.getImage());
                    Hibernate.initialize(shelf.getMap());
                }
            }
        }
    }
    return result;
}

From source file:com.pkrete.locationservice.endpoint.dao.locations.LocationsDao.java

License:Open Source License

/**
 * Returns the collection which location id matches the given id. All the
 * lazy relationships are loaded.//from   w  ww  .  ja v  a  2  s  .com
 *
 * @param id location id to be searched
 * @return collection matching the given location id
 */
@Override
public LibraryCollection getCollection(int id) {
    List<LibraryCollection> list = (List<LibraryCollection>) getHibernateTemplate().findByNamedParam(
            "from LibraryCollection as loc " + "left join fetch loc.image " + "left join fetch loc.map "
                    + "left join fetch loc.areas " + "where loc.locationId = :id",
            "id", id);
    if (list.isEmpty()) {
        return null;
    }
    LibraryCollection col = list.get(0);
    Hibernate.initialize(col.getNotes());
    Hibernate.initialize(col.getDescriptions());
    Hibernate.initialize(col.getSubjectMatters());
    Hibernate.initialize(col.getLibrary().getNotes());
    Hibernate.initialize(col.getLibrary().getDescriptions());
    Hibernate.initialize(col.getLibrary().getAreas());
    Hibernate.initialize(col.getLibrary().getImage());
    Hibernate.initialize(col.getLibrary().getMap());
    return col;
}

From source file:com.pkrete.locationservice.endpoint.dao.locations.LocationsDao.java

License:Open Source License

/**
 * Returns all the collections which id is in the given list. All the lazy
 * relationships are loaded. If children is true, all the shelves belonging
 * to the collections are loaded too./*www  .j a v  a 2  s  .c o m*/
 *
 * @param ids list of ids
 * @param children if true, all the shelves belonging to the collections are
 * loaded
 * @return collections matching the given ids
 */
@Override
public List<LibraryCollection> getCollections(List<Integer> ids, boolean children) {
    List<LibraryCollection> list = (List<LibraryCollection>) getHibernateTemplate()
            .findByNamedParam("select distinct loc from LibraryCollection as loc "
                    + "left join fetch loc.image " + "left join fetch loc.map " + "left join fetch loc.areas "
                    + "where loc.locationId in (:ids) ", "ids", ids);
    for (LibraryCollection col : list) {
        Hibernate.initialize(col.getNotes());
        Hibernate.initialize(col.getDescriptions());
        Hibernate.initialize(col.getSubjectMatters());
        Hibernate.initialize(col.getLibrary());
        if (children) {
            for (Shelf shelf : col.getShelves()) {
                Hibernate.initialize(shelf.getNotes());
                Hibernate.initialize(shelf.getDescriptions());
                Hibernate.initialize(shelf.getSubjectMatters());
                Hibernate.initialize(shelf.getAreas());
                Hibernate.initialize(shelf.getImage());
                Hibernate.initialize(shelf.getMap());
            }
        }
    }
    return list;
}

From source file:com.pkrete.locationservice.endpoint.dao.locations.LocationsDao.java

License:Open Source License

/**
 * Returns the shelf which location id matches the given id. All the lazy
 * relationships are loaded.//  w  w w. ja  v  a2s .c  o  m
 *
 * @param id location id to be searched
 * @return shelf matching the given location id
 */
@Override
public Shelf getShelf(int id) {
    List<Shelf> list = (List<Shelf>) getHibernateTemplate()
            .findByNamedParam("from Shelf as loc " + "left join fetch loc.image " + "left join fetch loc.map "
                    + "left join fetch loc.areas " + "where loc.locationId = :id", "id", id);
    if (list.isEmpty()) {
        return null;
    }
    Shelf shelf = list.get(0);
    Hibernate.initialize(shelf.getNotes());
    Hibernate.initialize(shelf.getDescriptions());
    Hibernate.initialize(shelf.getSubjectMatters());
    Hibernate.initialize(shelf.getCollection().getNotes());
    Hibernate.initialize(shelf.getCollection().getDescriptions());
    Hibernate.initialize(shelf.getCollection().getSubjectMatters());
    Hibernate.initialize(shelf.getCollection().getAreas());
    Hibernate.initialize(shelf.getCollection().getImage());
    Hibernate.initialize(shelf.getCollection().getMap());
    Hibernate.initialize(shelf.getCollection().getLibrary().getNotes());
    Hibernate.initialize(shelf.getCollection().getLibrary().getDescriptions());
    Hibernate.initialize(shelf.getCollection().getLibrary().getAreas());
    Hibernate.initialize(shelf.getCollection().getLibrary().getImage());
    Hibernate.initialize(shelf.getCollection().getLibrary().getMap());
    return shelf;
}

From source file:com.pkrete.locationservice.endpoint.dao.locations.LocationsDao.java

License:Open Source License

/**
 * Returns all the shelves which id is in the given list. All the lazy
 * relationships are loaded./* w w  w .  j a va 2  s.  co  m*/
 *
 * @param ids list of ids
 * @return shelves matching the given ids
 */
@Override
public List<Shelf> getShelves(List<Integer> ids) {
    List<Shelf> list = (List<Shelf>) getHibernateTemplate().findByNamedParam(
            "select distinct loc from Shelf as loc " + "left join fetch loc.image " + "left join fetch loc.map "
                    + "left join fetch loc.areas " + "where loc.locationId in (:ids)",
            "ids", ids);
    for (Shelf shelf : list) {
        Hibernate.initialize(shelf.getNotes());
        Hibernate.initialize(shelf.getDescriptions());
        Hibernate.initialize(shelf.getSubjectMatters());
        Hibernate.initialize(shelf.getCollection());
        Hibernate.initialize(shelf.getCollection().getLibrary());
    }
    return list;
}

From source file:com.pkrete.locationservice.endpoint.dao.locations.LocationsDao.java

License:Open Source License

/**
 * Returns the collection with the given collection code. If the collection
 * with the given code doesn't exist, null is returned.
 *
 * @param owner owner of the location//  w ww .  ja  va2 s. com
 * @param collectionCode collection code of the collection to be searched
 * @return collection matching the given code or null
 */
@Override
public LibraryCollection getCollectionByCollectionCode(String owner, String collectionCode) {
    List<LibraryCollection> result = (List<LibraryCollection>) getHibernateTemplate().findByNamedParam(
            "from LibraryCollection c " + "left join fetch c.image " + "left join fetch c.map "
                    + "left join fetch c.areas " + "where c.collectionCode = :collectionCode "
                    + "and c.owner.code = :owner",
            new String[] { "collectionCode", "owner" }, new Object[] { collectionCode, owner });
    if (result.isEmpty()) {
        return null;
    }
    LibraryCollection col = result.get(0);
    Hibernate.initialize(col.getNotes());
    Hibernate.initialize(col.getDescriptions());
    Hibernate.initialize(col.getSubjectMatters());
    Hibernate.initialize(col.getLibrary().getNotes());
    Hibernate.initialize(col.getLibrary().getDescriptions());
    Hibernate.initialize(col.getLibrary().getAreas());
    Hibernate.initialize(col.getLibrary().getImage());
    Hibernate.initialize(col.getLibrary().getMap());
    return col;
}

From source file:com.pkrete.locationservice.endpoint.dao.locations.LocationsDao.java

License:Open Source License

/**
 * Returns a list of all the libraries in the database that are related to
 * the given owner. All the lazy relationships are loaded.
 *
 * @param owner owner of the object//from  w w  w .  j  a v  a2s  . co  m
 * @return all the libraries in the database
 */
@Override
public List<Library> getAllLocations(String owner) {
    List<Library> result = (List<Library>) getHibernateTemplate().findByNamedParam(
            "select distinct lib from Library lib " + "left join fetch lib.image " + "left join fetch lib.map "
                    + "left join fetch lib.areas " + "where lib.owner.code = :owner",
            "owner", owner);
    for (Library lib : result) {
        Hibernate.initialize(lib.getNotes());
        Hibernate.initialize(lib.getDescriptions());
        for (LibraryCollection col : lib.getCollections()) {
            Hibernate.initialize(col.getNotes());
            Hibernate.initialize(col.getDescriptions());
            Hibernate.initialize(col.getSubjectMatters());
            Hibernate.initialize(col.getAreas());
            Hibernate.initialize(col.getImage());
            Hibernate.initialize(col.getMap());
            for (Shelf shelf : col.getShelves()) {
                Hibernate.initialize(shelf.getNotes());
                Hibernate.initialize(shelf.getDescriptions());
                Hibernate.initialize(shelf.getSubjectMatters());
                Hibernate.initialize(shelf.getAreas());
                Hibernate.initialize(shelf.getImage());
                Hibernate.initialize(shelf.getMap());
            }
        }
    }
    return result;
}

From source file:com.pl.controllers.UserController.java

@RequestMapping(value = "/login", method = RequestMethod.POST)
public String DoLogin(Model model, @ModelAttribute("user") User user, BindingResult result) {
    UserLoginValidator ulv = new UserLoginValidator();
    ulv.login(user, result, userDao);//from w ww. j  a v a2s.c  o  m

    if (result.hasErrors()) {
        return "login";
    }

    session.setAttribute("user", ulv.getUser());
    Hibernate.initialize(user.getSection());
    if (!sectionDao.findByManager(user.getUsername()).isEmpty()) {
        session.setAttribute("isManager", true);
    } else {
        session.setAttribute("isManager", false);
    }
    /*
    User user = usersDao.findByUsernameAndPassword(username, password);
    if (user == null) {
            
    model.addAttribute("errors", result.getAllErrors());
    return "login";
    }
    if (!sectionDao.findByManager(user.getUsername()).isEmpty()) {
    session.setAttribute("isManager", true);
    } else {
    session.setAttribute("isManager", false);
    }
    session.setAttribute("user", user);
            
    */
    return "redirect:/member";
}

From source file:com.project.framework.dao.ContinenteDaoImpl.java

@Override
public List<Continente> getContinentesConIdioma() {
    List<Continente> continentes = getSession().createQuery("from Continente").list();
    for (Continente continente : continentes) {
        Hibernate.initialize(continente.getIdiomas());
    }//from   ww w.  j av a2 s. c om
    return continentes;
}

From source file:com.qrmedia.commons.persistence.hibernate.clone.example.EntityClonerDemo.java

License:Open Source License

@Test
@Ignore/*from w ww .j av  a2s. com*/
public void xStreamSerialize() {
    Pet garfield = (Pet) session.get(Pet.class, garfieldId);
    System.out.println(xStream.toXML(garfield));

    Owner jon = (Owner) session.createCriteria(Owner.class).uniqueResult();
    Hibernate.initialize(jon.getPets());
    System.out.println(xStream.toXML(jon));
}