Session save - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Session save method.

This code example shows how to use the following methods:save
	protected <T> T find(Class<T> entityClass, Serializable id) {
		return (T)session.load(entityClass, id);
	} 
	@Override 
	protected <T> T save(T entity) {
		session.save(entity);
		return entity;
	} 
	@SuppressWarnings("unchecked") 
	@Override 
	protected <T> T merge(T entity) {
		return (T)session.merge(entity);
	} 
	@Override 
	protected void flush() { 
		session.flush();
		tx.commit();
	} 
	@Override 
	protected void close() { 
7
CodeRank
This code example shows how to use the following methods:flush, save
 
		Person ups = new Person( "UPS guy" );
		ups.setCompany( "UPS" );
		ups.setRegion( "US" );
 
		s.save( john );
		s.save( cust );
		s.save( ups );
 
		s.flush();
	} 
 
} 
7
CodeRank
This code example shows how to use the following methods:save
	protected <T> T find(Class<T> entityClass, Serializable id) {
		return (T)session.load(entityClass, id);
	} 
	@Override 
	protected <T> T save(T entity) {
		session.save(entity);
		return entity;
	} 
	@SuppressWarnings("unchecked") 
	@Override 
	protected <T> T merge(T entity) {
		return (T)session.merge(entity);
	} 
	@Override 
	protected void flush() { 
		session.flush();
		tx.commit();
	} 
	@Override 
	protected void close() { 
7
CodeRank
This code example shows how to use the following methods:close, flush, save, beginTransaction
 
	private void populateDatabase() { 
		Session session = openSession();
 
		try { 
			Transaction t = session.beginTransaction();
 
			ConcreteEntity entity = new ConcreteEntity();
			session.save( entity );
			entityId = entity.getId();
 
			LazyAbstractEntityReference reference = new LazyAbstractEntityReference( entity );
			session.save( reference );
			entityReferenceId = reference.getId();
 
			session.flush();
			t.commit();
		} 
		finally { 
			session.close();

7
CodeRank
This code example shows how to use the following methods:close, save, beginTransaction
	} 
 
	private void prepareEntities(String level3Name) {
		Session session = openSession();
		try { 
			Transaction transaction = session.beginTransaction();
 
			Level1 level1 = new Level1();
			DerivedLevel2 level2 = new DerivedLevel2();
			Level3 level3 = new Level3();
 
			level1.setLevel2Child( level2 );
			level2.setLevel1Parent( level1 );
			level2.setLevel3Child( level3 );
			level3.setLevel2Parent( level2 );
 
			level3.setName( level3Name );
 
			session.save( level1 );
			session.save( level2 );

7
CodeRank
This code example shows how to use the following methods:save
 
    public DeploymentUnitDAO createDeploymentUnit(String name) {
        DeploymentUnitDaoImpl du = new DeploymentUnitDaoImpl();
        du.setName(name);
        du.setDeployDate(new Date());
        _session.save(du);
        return du;
    } 
 
    public DeploymentUnitDAO getDeploymentUnit(String name) {
        try { 
            DeploymentUnitDaoImpl du = (DeploymentUnitDaoImpl) _session.get(DeploymentUnitDaoImpl.class,name);
            return du;
        } catch (HibernateException e) {
            __log.error("DbError", e);
            throw e;
        } 
    } 
 
    public long getNextVersion() { 
7
CodeRank
This code example shows how to use the following methods:close, save, beginTransaction
	} 
 
	private void prepareEntities() { 
		Session session = openSession();
		try { 
			Transaction transaction = session.beginTransaction();
 
			LazyItem bridgedEntity = new LazyItem();
			session.save( bridgedEntity );
 
			Leaf leaf = new Leaf();
			leaf.setLazyItem( bridgedEntity );
			session.save( leaf );
 
			Root root = new Root();
			root.setName( "name" );
			root.setLeaf( leaf );
			session.save( root );
 
			transaction.commit();

7
CodeRank
This code example shows how to use the following methods:close, flush, save, beginTransaction, createQuery
		CmsLog cmslog = new CmsLog();
		cmslog.setCategory(10);
		cmslog.setIp("192.167.1");
		Date d = new Date();
		cmslog.setTime(d);
		Transaction tx = session.beginTransaction();
		session.save(cmslog);
		session.flush();// 清空缓存后customer对象处于游离状态
		tx.commit();
 
		System.out.println("Save Data success!");
		int recordCount = session.createQuery(
				"from  com.jeecms.cms.entity.main.CmsLog ").list().size();
 
		System.out.println("查询到数据jc_log表数据:" + recordCount + "条");
		session.close();
 
	} 
 
	@Test
	public void testFromSqlGetData() { 
6
CodeRank
This code example shows how to use the following methods:close, save, beginTransaction, getTransaction
		return new String[] { "orphan/one2one/fk/reversed/bidirectional/Mapping.hbm.xml" };
	} 
 
	private void createData() { 
		Session session = openSession();
		session.beginTransaction();
		Employee emp = new Employee();
		emp.setInfo( new EmployeeInfo( emp ) );
		session.save( emp );
		session.getTransaction().commit();
		session.close();
	} 
 
	private void cleanupData() { 
		Session session = openSession();
		session.beginTransaction();
		session.createQuery( "delete EmployeeInfo" ).executeUpdate();
		session.createQuery( "delete Employee" ).executeUpdate();
		session.getTransaction().commit();
		session.close();
6
CodeRank
This code example shows how to use the following methods:close, delete, save, beginTransaction, createQuery
	public void testJoinedSubclass() { 
		Statistics statistics = sessionFactory().getStatistics();
		statistics.clear();
		 
		Session s = openSession();
		Transaction t = s.beginTransaction();
		 
		Salesperson mark = new Salesperson();
		mark.setName("Mark");
		mark.setTitle("internal sales");
		mark.setSex('M');
		mark.setAddress("buckhead");
		mark.setZip("30305");
		mark.setCountry("USA");
		 
		Person joe = new Person();
		joe.setName("Joe");
		joe.setAddress("San Francisco");
		joe.setZip("XXXXX");
		joe.setCountry("USA");

6
CodeRank
save Method Overview
Persist the given transient instance, first assigning a generated identifier.
See Code Examples for other Hibernate ORM Session Methods: