@SuppressWarnings("unchecked")
	void run(EntityManager entityManager) throws Exception {

		String queryStr;
		Query query = null;


		while(true) {

			try {
				queryStr = mode == Mode.CONSOLE ? 
					console.readLine("Enter JPA Query: ") :
					JOptionPane.showInputDialog(null, "Enter JPA Query: ");
				if (queryStr == null || "quit".equals(queryStr)) {
					return;
				}
	
				query = entityManager.createQuery(queryStr);
	
				List<Object> list = query.getResultList();
				System.out.println("Found " + list.size() + " results:");
				for (Object o : list) {
					System.out.println(o);
				}
				System.out.println();
			} catch (Exception e) {
				System.out.println("Error: " + e);
				e.printStackTrace();
			}
		}

	}