users@glassfish.java.net

Re: Question on JPA _at_SqlResultSetMapping when using a native query

From: <glassfish_at_javadesktop.org>
Date: Mon, 25 Aug 2008 09:49:58 PDT

Hi.
This is what i did, and it works as expected:

@Stateless(name="ImagesServiceImpl")
public class ImagesServiceImpl implements ImagesService {

    @PersistenceContext
    EntityManager em;
    
    public Long getNewImageId() {
        Query q = em.createNativeQuery(
            "SELECT nextval('global_next_image_id_seq') AS ID");
        try {
            return (Long)((List) q.getSingleResult()).get(0);
        }
        catch(Exception ex) {
            throw new RuntimeException(ex.getMessage(), ex);
        }
    }

}
[Message sent by forum member 'frank_martinez' (frank_martinez)]

http://forums.java.net/jive/thread.jspa?messageID=295165