public static boolean createOrders(List<OrderInfo> orders, int eventId,
			int userId) throws HibernateException {
		boolean isCreateOrdersSuccessful = false;
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		try {
			// Begin unit of work
			session.beginTransaction();

			Calendar calendar = new GregorianCalendar();

			// Check the old available orders for per user
			String hql = "select o from OrderInfo as o where o.orderStatus>0 and o.userId="
					+ userId
					+ " and o.eventId="
					+ eventId
					+ " and DAYOFMONTH(o.createDate)="
					+ calendar.get(Calendar.DAY_OF_MONTH)
					+ " and MONTH(o.createDate)="
					+ (calendar.get(Calendar.MONTH) + 1)
					+ " and YEAR(o.createDate)="
					+ calendar.get(Calendar.YEAR)
					+ " order by o.foodId";

			Query query = session.createQuery(hql);

			@SuppressWarnings("unchecked")
			List<OrderInfo> oldOrders = query.list();

			// User has already ordered in this event, then do the update old
			// orders by count and comment
			if (oldOrders.size() > 0) {
				Collections.sort(orders);
				for (int i = 0; i < orders.size(); i++) {
					boolean isMatched = false;
					for (int j = i; j < oldOrders.size(); j++) {
						OrderInfo oldOrder = oldOrders.get(j);
						OrderInfo newOrder = orders.get(i);
						if (oldOrder.getFoodId() == newOrder.getFoodId()) {
							oldOrder.setFoodCount(newOrder.getFoodCount());
							oldOrder.setComment(newOrder.getComment());
							isMatched = true;
							session.save(oldOrder);
							break;
						}
					}
					if (!isMatched) {
						OrderInfo newOrder = orders.get(i);
						newOrder.setOrderStatus(1);
						session.save(newOrder);
					}
				}
				// End unit of work
				session.getTransaction().commit();
			}
			// User hasn't ordered yet, then save the whole orders
			else {
				for (int i = 0; i < orders.size(); i++) {
					session.save(orders.get(i));
				}
				EventDAO.addUserToEvent(eventId, userId);
			}
			isCreateOrdersSuccessful = true;
		} catch (HibernateException hex) {
			logger.error(hex.toString());
			HibernateUtil.getSessionFactory().getCurrentSession()
					.getTransaction().rollback();
		} catch (Exception ex) {
			logger.error(ex.toString());
			HibernateUtil.getSessionFactory().getCurrentSession()
					.getTransaction().rollback();
		}
		return isCreateOrdersSuccessful;
	}