Java Code Examples for org.hibernate.HibernateException#printStackTrace()

The following examples show how to use org.hibernate.HibernateException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfidenceStatisticsResourceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public List<ConfidenceData> getDataAfterTimestampGranularityInBin(String crisisCode, String attributeCode, String labelCode,
																	Long timestamp, Long granularity, Integer bin) {
	Criteria criteria = getCurrentSession().createCriteria(ConfidenceData.class);
	Criterion criterion = Restrictions.conjunction()
			.add(Restrictions.eq("crisisCode", crisisCode))
			.add(Restrictions.eq("attributeCode", attributeCode))
			.add(Restrictions.eq("labelCode", labelCode))
			.add(Restrictions.ge("timestamp", timestamp))
			.add(Restrictions.eq("granularity", granularity))
			.add(Restrictions.eq("bin", bin));
			
	criteria.add(criterion); 		
	try {
		List<ConfidenceData> objList = (List<ConfidenceData>) criteria.list();
		return objList;
	} catch (HibernateException e) {
		logger.error("exception", e);
		e.printStackTrace();
	}
	return null;
}
 
Example 2
Source File: ConfidenceStatisticsResourceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public List<ConfidenceData> getDataByCrisisInBin(String crisisCode, Integer bin) {
	Criteria criteria = getCurrentSession().createCriteria(ConfidenceData.class);
	Criterion criterion = Restrictions.conjunction()
			.add(Restrictions.eq("crisisCode", crisisCode))
			.add(Restrictions.eq("bin", bin));
	criteria.add(criterion); 
	try {
		List<ConfidenceData> objList = (List<ConfidenceData>) criteria.list();
		return objList;
	} catch (HibernateException e) {
		logger.error("exception", e);
		e.printStackTrace();
	}
	return null;
}
 
Example 3
Source File: ConfidenceStatisticsResourceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public List<ConfidenceData> getDataBeforeTimestamp(String crisisCode, String attributeCode, String labelCode, Long timestamp) {
	Criteria criteria = getCurrentSession().createCriteria(ConfidenceData.class);
	Criterion criterion = Restrictions.conjunction()
			.add(Restrictions.eq("crisisCode", crisisCode))
			.add(Restrictions.eq("attributeCode", attributeCode))
			.add(Restrictions.eq("labelCode", labelCode))
			.add(Restrictions.le("timestamp", timestamp));
			
	criteria.add(criterion); 		
	try {
		List<ConfidenceData> objList = (List<ConfidenceData>) criteria.list();
		return objList;
	} catch (HibernateException e) {
		logger.error("exception", e);
		e.printStackTrace();
	}
	return null;
}
 
Example 4
Source File: ConfidenceStatisticsResourceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public List<ConfidenceData> getDataAfterTimestampGranularity(String crisisCode, String attributeCode, String labelCode,
															Long timestamp, Long granularity) {
	Criteria criteria = getCurrentSession().createCriteria(ConfidenceData.class);
	Criterion criterion = Restrictions.conjunction()
			.add(Restrictions.eq("crisisCode", crisisCode))
			.add(Restrictions.eq("attributeCode", attributeCode))
			.add(Restrictions.eq("labelCode", labelCode))
			.add(Restrictions.ge("timestamp", timestamp))
			.add(Restrictions.eq("granularity", granularity));
			
	criteria.add(criterion); 		
	try {
		List<ConfidenceData> objList = (List<ConfidenceData>) criteria.list();
		return objList;
	} catch (HibernateException e) {
		logger.error("exception", e);
		e.printStackTrace();
	}
	return null;
}
 
Example 5
Source File: ConfidenceStatisticsResourceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public List<ConfidenceData> getDataByCrisisAttributeLabelGranularityWithBin(String crisisCode, String attributeCode, String labelCode,
																	Long granularity, Integer bin) {
	Criteria criteria = getCurrentSession().createCriteria(ConfidenceData.class);
	Criterion criterion = Restrictions.conjunction()
			.add(Restrictions.eq("crisisCode", crisisCode))
			.add(Restrictions.eq("attributeCode", attributeCode))
			.add(Restrictions.eq("labelCode", labelCode))
			.add(Restrictions.eq("granularity", granularity))
			.add(Restrictions.ge("bin", bin));
	criteria.add(criterion); 		
	try {
		List<ConfidenceData> objList = (List<ConfidenceData>) criteria.list();
		return objList;
	} catch (HibernateException e) {
		logger.error("exception", e);
		e.printStackTrace();
	}
	return null;
}
 
Example 6
Source File: ConfidenceStatisticsResourceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public List<ConfidenceData> getDataInInterval(String crisisCode, String attributeCode, String labelCode, Long timestamp1, Long timestamp2) {
	Criteria criteria = getCurrentSession().createCriteria(ConfidenceData.class);
	Criterion criterion = Restrictions.conjunction()
			.add(Restrictions.eq("crisisCode", crisisCode))
			.add(Restrictions.eq("attributeCode", attributeCode))
			.add(Restrictions.eq("labelCode", labelCode))
			.add(Restrictions.ge("timestamp", timestamp1))
			.add(Restrictions.le("timestamp", timestamp2));
			
	criteria.add(criterion); 		
	try {
		List<ConfidenceData> objList = (List<ConfidenceData>) criteria.list();
		return objList;
	} catch (HibernateException e) {
		logger.error("exception", e);
		e.printStackTrace();
	}
	return null;
}
 
Example 7
Source File: ConfidenceStatisticsResourceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public List<ConfidenceData> getDataBeforeTimestampInBin(String crisisCode, String attributeCode, String labelCode, 
																	Long timestamp, Integer bin) {
	Criteria criteria = getCurrentSession().createCriteria(ConfidenceData.class);
	Criterion criterion = Restrictions.conjunction()
			.add(Restrictions.eq("crisisCode", crisisCode))
			.add(Restrictions.eq("attributeCode", attributeCode))
			.add(Restrictions.eq("labelCode", labelCode))
			.add(Restrictions.le("timestamp", timestamp))
			.add(Restrictions.eq("bin", bin));
			
	criteria.add(criterion); 		
	try {
		List<ConfidenceData> objList = (List<ConfidenceData>) criteria.list();
		return objList;
	} catch (HibernateException e) {
		logger.error("exception", e);
		e.printStackTrace();
	}
	return null;
}
 
Example 8
Source File: ConfidenceStatisticsResourceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public List<ConfidenceData> getDataByCrisisWithBin(String crisisCode, Integer bin) {
	Criteria criteria = getCurrentSession().createCriteria(ConfidenceData.class);
	Criterion criterion = Restrictions.conjunction()
			.add(Restrictions.eq("crisisCode", crisisCode))
			.add(Restrictions.ge("bin", bin));
	criteria.add(criterion); 
	try {
		List<ConfidenceData> objList = (List<ConfidenceData>) criteria.list();
		return objList;
	} catch (HibernateException e) {
		logger.error("exception", e);
		e.printStackTrace();
	}
	return null;
}
 
Example 9
Source File: ConfidenceStatisticsResourceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public List<ConfidenceData> getDataInIntervalInBin(String crisisCode, String attributeCode, String labelCode, Long timestamp1,
																	Long timestamp2, Integer bin) {
	Criteria criteria = getCurrentSession().createCriteria(ConfidenceData.class);
	Criterion criterion = Restrictions.conjunction()
			.add(Restrictions.eq("crisisCode", crisisCode))
			.add(Restrictions.eq("attributeCode", attributeCode))
			.add(Restrictions.eq("labelCode", labelCode))
			.add(Restrictions.ge("timestamp", timestamp1))
			.add(Restrictions.le("timestamp", timestamp2))
			.add(Restrictions.eq("bin", bin));
			
	criteria.add(criterion); 		
	try {
		List<ConfidenceData> objList = (List<ConfidenceData>) criteria.list();
		return objList;
	} catch (HibernateException e) {
		logger.error("exception", e);
		e.printStackTrace();
	}
	return null;
}
 
Example 10
Source File: ConfidenceStatisticsResourceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public List<ConfidenceData> getDataInIntervalWithGranularity(String crisisCode, String attributeCode, String labelCode, 
																Long timestamp1, Long timestamp2, Long granularity) {
	Criteria criteria = getCurrentSession().createCriteria(ConfidenceData.class);
	Criterion criterion = Restrictions.conjunction()
			.add(Restrictions.eq("crisisCode", crisisCode))
			.add(Restrictions.eq("attributeCode", attributeCode))
			.add(Restrictions.eq("labelCode", labelCode))
			.add(Restrictions.eq("granularity", granularity))
			.add(Restrictions.ge("timestamp", timestamp1))
			.add(Restrictions.le("timestamp", timestamp2));
			
	criteria.add(criterion); 		
	try {
		List<ConfidenceData> objList = (List<ConfidenceData>) criteria.list();
		return objList;
	} catch (HibernateException e) {
		logger.error("exception", e);
		e.printStackTrace();
	}
	return null;
}
 
Example 11
Source File: ConfidenceStatisticsResourceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public List<ConfidenceData> getDataBeforeTimestampWithBin(String crisisCode, String attributeCode, String labelCode, 
																	Long timestamp, Integer bin) {
	Criteria criteria = getCurrentSession().createCriteria(ConfidenceData.class);
	Criterion criterion = Restrictions.conjunction()
			.add(Restrictions.eq("crisisCode", crisisCode))
			.add(Restrictions.eq("attributeCode", attributeCode))
			.add(Restrictions.eq("labelCode", labelCode))
			.add(Restrictions.le("timestamp", timestamp))
			.add(Restrictions.ge("bin", bin));
			
	criteria.add(criterion); 		
	try {
		List<ConfidenceData> objList = (List<ConfidenceData>) criteria.list();
		return objList;
	} catch (HibernateException e) {
		logger.error("exception", e);
		e.printStackTrace();
	}
	return null;
}
 
Example 12
Source File: RatingService.java    From auction-website with MIT License 6 votes vote down vote up
/**
 * @param from_id from userId
 * @param to_id to userId
 * @param aid auctionId
 * @param rating rating
 */
public void updateRating(long from_id, long to_id, long aid, int rating) {
    Session session = HibernateUtil.getSession();
    try {
        session.beginTransaction();
        RatingEntity ratingEntity = getRating(from_id, to_id, aid);
        ratingEntity.setRating(rating);
        session.update(ratingEntity);
        session.getTransaction().commit();
    } catch (HibernateException e) {
        e.printStackTrace();
    } finally {
        try {
            if (session != null) session.close();
        } catch (Exception ignored) {}
    }
}
 
Example 13
Source File: RatingService.java    From auction-website with MIT License 6 votes vote down vote up
/**
 * @param uid userId
 * @param rating_t ratings From or To
 * @return all ratings that a user has placed, or have been placed for him
 */
public List<RatingEntity> getFromOrToRatings(long uid, Rating_t rating_t) {
    Session session = HibernateUtil.getSession();
    Query query = null;
    List<RatingEntity> ratingEntities = null;
    try {
        switch (rating_t) {
            case From_t:
                query = session.createQuery("from RatingEntity where fromId = :uid");
                break;
            case To_t:
                query = session.createQuery("from RatingEntity where toId = :uid");
                break;
        }
        ratingEntities = (query != null) ? query.setParameter("uid", uid).list() : null;
    } catch (HibernateException e) {
        e.printStackTrace();
    } finally {
        try {
            if (session != null) session.close();
        } catch (Exception ignored) {}
    }
    return ratingEntities;
}
 
Example 14
Source File: BidService.java    From auction-website with MIT License 6 votes vote down vote up
/**
 * @param uid userId
 * @return a list of auction-ids that user with uid has bided
 */
public List getAllUserBids(long uid) {
    Session session = HibernateUtil.getSession();
    List bids = null;
    try {
        Criteria criteria = session.createCriteria( BidEntity.class );
        criteria.add(Restrictions.eq("bidderId", uid));
        criteria.setProjection( Projections.distinct( Projections.property( "auctionId" ) ));
        criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
        bids = criteria.list();
    } catch (HibernateException e) {
        e.printStackTrace();
    } finally {
        try { if (session != null) session.close(); } catch (Exception ignored) {}
    }
    return bids;
}
 
Example 15
Source File: ConfidenceStatisticsResourceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public List<ConfidenceData> getDataByCrisisAttributeLabelInBin(String crisisCode, String attributeCode, String labelCode,
																	Integer bin) {
	Criteria criteria = getCurrentSession().createCriteria(ConfidenceData.class);
	Criterion criterion = Restrictions.conjunction()
			.add(Restrictions.eq("crisisCode", crisisCode))
			.add(Restrictions.eq("attributeCode", attributeCode))
			.add(Restrictions.eq("labelCode", labelCode))
			.add(Restrictions.eq("bin", bin));
	criteria.add(criterion); 		
	try {
		List<ConfidenceData> objList = (List<ConfidenceData>) criteria.list();
		return objList;
	} catch (HibernateException e) {
		logger.error("exception", e);
		e.printStackTrace();
	}
	return null;
}
 
Example 16
Source File: ConfidenceStatisticsResourceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public List<ConfidenceData> getDataInIntervalWithGranularityInBin(String crisisCode, String attributeCode, String labelCode,
																	Long timestamp1, Long timestamp2, Long granularity, Integer bin) {
	Criteria criteria = getCurrentSession().createCriteria(ConfidenceData.class);
	Criterion criterion = Restrictions.conjunction()
			.add(Restrictions.eq("crisisCode", crisisCode))
			.add(Restrictions.eq("attributeCode", attributeCode))
			.add(Restrictions.eq("labelCode", labelCode))
			.add(Restrictions.eq("granularity", granularity))
			.add(Restrictions.ge("timestamp", timestamp1))
			.add(Restrictions.le("timestamp", timestamp2))
			.add(Restrictions.eq("bin", bin));
			
	criteria.add(criterion); 		
	try {
		List<ConfidenceData> objList = (List<ConfidenceData>) criteria.list();
		return objList;
	} catch (HibernateException e) {
		logger.error("exception", e);
		e.printStackTrace();
	}
	return null;
}
 
Example 17
Source File: BIObjectDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Load bi object by label.
 *
 * @param label the label
 * @return the BI object
 * @throws EMFUserError the EMF user error
 * @see it.eng.spagobi.analiticalmodel.document.dao.IBIObjectDAO#loadBIObjectByLabel(java.lang.String)
 */
@Override
public BIObject loadBIObjectByLabel(String label) throws EMFUserError {
	logger.debug("IN");
	BIObject biObject = null;
	Session aSession = null;
	Transaction tx = null;
	try {
		aSession = getSession();
		tx = aSession.beginTransaction();
		Criterion labelCriterrion = Expression.eq("label", label);
		Criteria criteria = aSession.createCriteria(SbiObjects.class);
		criteria.add(labelCriterrion);
		SbiObjects hibObject = (SbiObjects) criteria.uniqueResult();
		if (hibObject != null) {
			biObject = toBIObject(hibObject, aSession);
		} else {
			logger.warn("Unable to load document whose label is equal to [" + label + "]");
		}
		tx.commit();
	} catch (HibernateException he) {
		logger.error(he);
		he.printStackTrace();
		if (tx != null)
			tx.rollback();
		throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
	} finally {
		if (aSession != null) {
			if (aSession.isOpen())
				aSession.close();
		}
	}
	logger.debug("OUT");
	return biObject;
}
 
Example 18
Source File: FooFixtures.java    From tutorials with MIT License 5 votes vote down vote up
public void createBars() {
    Session session = null;
    Transaction tx = null;
    session = sessionFactory.openSession();
    tx = session.getTransaction();
    try {
        tx.begin();
        for (int i = 156; i < 160; i++) {
            final Bar bar = new Bar();
            bar.setName("Bar_" + i);
            final Foo foo = new Foo("Foo_" + (i + 120));
            foo.setBar(bar);
            session.save(foo);
            final Foo foo2 = new Foo(null);
            if (i % 2 == 0)
                foo2.setName("LuckyFoo" + (i + 120));
            foo2.setBar(bar);
            session.save(foo2);
            bar.getFooSet().add(foo);
            bar.getFooSet().add(foo2);
            session.merge(bar);
        }
        tx.commit();
        session.flush();
    } catch (final HibernateException he) {
        if (tx != null)
            tx.rollback();
        System.out.println("Not able to open session");
        he.printStackTrace();
    } catch (final Exception e) {
        e.printStackTrace();
    } finally {
        if (session != null)
            session.close();
    }

}
 
Example 19
Source File: ExtendsTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testNwaitingForSuper() {
	Configuration cfg = new Configuration();

	try {
		cfg.addResource( getBaseForMappings() + "extendshbm/Customer.hbm.xml" );
		assertNull(
				"cannot be in the configuration yet!",
				cfg.getClassMapping( "org.hibernate.test.extendshbm.Customer" )
		);
		cfg.addResource( getBaseForMappings() + "extendshbm/Employee.hbm.xml" );
		assertNull(
				"cannot be in the configuration yet!",
				cfg.getClassMapping( "org.hibernate.test.extendshbm.Employee" )
		);
		cfg.addResource( getBaseForMappings() + "extendshbm/Person.hbm.xml" );

		cfg.buildMappings();

		assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Person" ) );
		assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Employee" ) );
		assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Customer" ) );


	}
	catch ( HibernateException e ) {
		e.printStackTrace();
		fail( "should not fail with exception! " + e );

	}

}
 
Example 20
Source File: Service.java    From auction-website with MIT License 5 votes vote down vote up
public void addEntity(Object entity) {
    Session session = HibernateUtil.getSession();
    try {
        session.beginTransaction();
        session.save(entity);
        session.getTransaction().commit();
    } catch (HibernateException e) {
        e.printStackTrace();
    } finally {
        try {
            if (session != null) session.close();
        } catch (Exception ignored) {}
    }
}