The Source for Java Technology Collaboration
User: Password:



Manfred Riem

Manfred Riem's Blog

JPA Tip #1 - Native Queries

Posted by mriem on August 22, 2007 at 11:30 AM | Comments (0)

OK, native queries in JPA. Not really well documented. Of course I understand that we really should not be doing that, but hey there are times where it is just plain easier. The following code snippet goes after an Oracle sequence and gets the value.
EntityManager em = this.getEntityManager();
Query query = em.createNativeQuery("SELECT BLOG_ITEM_SEQ.nextval FROM DUAL");
Vector blogItemRow = (Vector) query.getSingleResult();
Integer blogItemId = (Integer) blogItemRow.elementAt(0);
As you can see by reading the Java code if you do a native query you can map the result to a Vector and then for each row you have a Vector for all the columns. In this particular case only one and the first column is an Integer.

Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first)





Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds