Java Code Examples for org.hibernate.Session.load()

The following are Jave code examples for showing how to use load() of the org.hibernate.Session class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: bdf2   File: RoleMemberMaintain.java   Source Code and License Vote up 6 votes
@Expose
public void changeGranted(Collection<Map<String, Object>> members)
		throws Exception {
	getLoginUser();
	Session session = this.getSessionFactory().openSession();
	try {
		for (Map<String, Object> map : members) {
			RoleMember rm = (RoleMember) session.load(RoleMember.class,
					(String) map.get("memberId"));
			rm.setGranted((Boolean) map.get("granted"));
			session.update(rm);
		}
	} finally {
		session.flush();
		session.close();
	}
}
 
Example 2
Project: hibernate-springcache   File: EventManager.java   Source Code and License Vote up 5 votes
public List<String> listEmailsOfEvent(Long eventId) {
	Session session = sessionFactory.getCurrentSession();
	session.beginTransaction();

	List<String> emailList = new ArrayList<String>();
	Event event = session.load(Event.class, eventId);
	for (Iterator<Person> it = event.getParticipants().iterator(); it.hasNext(); ) {
		Person person = it.next();
		emailList.addAll(person.getEmailAddresses());
	}

	session.getTransaction().commit();
	return emailList;
}
 
Example 3
Project: hibernate-springcache   File: EventManager.java   Source Code and License Vote up 5 votes
public Long addPersonToAccount(Long personId, Account account) {
	Session session = sessionFactory.getCurrentSession();
	session.beginTransaction();

	Person aPerson = session.load(Person.class, personId);
	account.setPerson(aPerson);

	Long accountId = (Long)session.save(account);

	session.getTransaction().commit();
	return accountId;
}
 
Example 4
Project: hibernate-springcache   File: EventManager.java   Source Code and License Vote up 5 votes
public Account getAccount(Long accountId) {
	Session session = sessionFactory.getCurrentSession();
	session.beginTransaction();

	Account account = session.load(Account.class, accountId);

	session.getTransaction().commit();
	return account;
}
 
Example 5
Project: hibernate-springcache   File: EventManager.java   Source Code and License Vote up 5 votes
public void addPhoneNumberToPerson(Long personId, PhoneNumber pN) {

		Session session = sessionFactory.getCurrentSession();
		session.beginTransaction();

		Person aPerson = session.load(Person.class, personId);
		pN.setPersonId(personId.longValue());
		aPerson.getPhoneNumbers().add(pN);

		session.getTransaction().commit();
	}
 
Example 6
Project: hibernateMaster   File: DaoUtil.java   Source Code and License Vote up 5 votes
/**
 * 根据实体类id加载实体类
 * 
 * @param <T> 要加载的实体类
 * 
 * @param clazz 要加载的实体类
 * @param id 实体类id
 * 
 * @return 查询到的实体类的代理对象(记录不存则返回null)
 */
public final static <T extends BaseRelationalDatabaseDomain> T load(Class<T> clazz,Serializable id){
	try {
		Session session = getSession();
		return session.load(clazz, id);
	} catch (Exception e) {
		setException(e);
		return null;
	}finally{
		closeSession();
	}
}
 
Example 7
Project: sbc-qsystem   File: Spring.java   Source Code and License Vote up 5 votes
public void load(Object obj, Serializable srlzbl) {
    final Session ses = getTxManager().getSessionFactory().openSession();
    try {
        ses.load(obj, srlzbl);
    } finally {
        ses.close();
    }
}
 
Example 8
Project: bdf2   File: RoleMemberMaintain.java   Source Code and License Vote up 5 votes
@Expose
public void changeGranted(Collection<Map<String,Object>> members) throws Exception{
	Session session=this.getSessionFactory().openSession();
	try{
		for(Map<String,Object> map:members){
			RoleMember rm=(RoleMember)session.load(RoleMember.class,(String)map.get("memberId"));
			rm.setGranted((Boolean)map.get("granted"));
			session.update(rm);
		}			
	}finally{
		session.flush();
		session.close();
	}
}
 
Example 9
Project: sdudoc   File: BookDaoImpl.java   Source Code and License Vote up 4 votes
@Override
public Book getBookById(int bookId) {
	Session session = sessionFactory.getCurrentSession();
	Book book = (Book) session.load(Book.class, bookId);
	return book;
}
 
Example 10
Project: unitimes   File: _BaseRootDAO.java   Source Code and License Vote up 4 votes
/**
 * Used by the base DAO classes but here for your modification
 * Load object matching the given key and return it.
 */
@SuppressWarnings("unchecked")
protected T load(Class<T> refClass, K key, Session s) {
	return (T)s.load(refClass, key);
}
 
Example 11
Project: OSWf-OSWorkflow-fork   File: HibernateStore.java   Source Code and License Vote up 3 votes
protected HibernateProcessInstance loadEntry(Session session, final long piid) throws WorkflowStoreException {

        HibernateProcessInstance workflowEntry = (HibernateProcessInstance)session.load(HibernateProcessInstance.class, piid);
        
        // The next line forces the ORM to load the properties into the object; This should not be lazy loading
        //  but seems to be occuring; Access any property loads them all.  Work-around?

        workflowEntry.getState();
        return workflowEntry;
    }
 
Example 12
Project: Celebino   File: GenericDao.java   Source Code and License Vote up 3 votes
public boolean delete(Long id) throws SQLException {
	boolean isDelete = false;

	Session session = HibernateUtil.getSessionFactory().openSession();

	try {
		session.beginTransaction();

		T entity = (T) session.load(getEntityClass(), id);
		session.delete(entity);

		// This makes the pending delete to be done
		session.getTransaction().commit();

		isDelete = true;

	} catch (HibernateException hibernateException) {
		session.getTransaction().rollback();

		throw new SQLException(hibernateException);

	} finally {
		session.close();
	}

	return isDelete;
}
 
Example 13
Project: hibernate-springcache   File: EventManager.java   Source Code and License Vote up 3 votes
public void addPersonToEvent(Long personId, Long eventId) {

		Session session = sessionFactory.getCurrentSession();
		session.beginTransaction();

		Person aPerson = session.load(Person.class, personId);
		Event anEvent = session.load(Event.class, eventId);

		aPerson.getEvents().add(anEvent);

		session.getTransaction().commit();
	}
 
Example 14
Project: hibernate-springcache   File: EventManager.java   Source Code and License Vote up 3 votes
public void addEmailToPerson(Long personId, String emailAddress) {

		Session session = sessionFactory.getCurrentSession();
		session.beginTransaction();

		Person aPerson = session.load(Person.class, personId);

		// The getEmailAddresses() might trigger a lazy load of the collection
		aPerson.getEmailAddresses().add(emailAddress);

		session.getTransaction().commit();
	}
 
Example 15
Project: hibernate-springcache   File: EventManager.java   Source Code and License Vote up 3 votes
public void addTalismanToPerson(Long personId, String talisman) {

		Session session = sessionFactory.getCurrentSession();
		session.beginTransaction();

		Person aPerson = session.load(Person.class, personId);
		aPerson.addTalisman(talisman);

		session.getTransaction().commit();
	}