EntityManager – create native query

Posted: January 10, 2013 in web

private static final String TEMP = "select DISTINCT TOP 200 name, address FROM sometable";

public class StatsService {
    @PersistenceContext(unitName = "someDB")
    private EntityManager entityManager;

    public void runTEMP() {

        List<Object[]> result = entityManager.createNativeQuery(TEMP).getResultList();

        for (Object[] object : result) {
            if (object[0] != null) {
		System.out.println(objec[0]);  //shows name field
		System.out.println(objec[1]);  //shows address field



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s