5 Replies Latest reply on Dec 1, 2010 4:29 AM by Philippe Leménager

    How to perform a native SQL query?

    Scott Shepherd Newbie
      How do you execute a native SQL insert?

      Calling the broadcast() method below breaks with the stack trace further below.

      Any ideas?

      ---

      @Name("broadcaster")
      @Scope(ScopeType.CONVERSATION)
      public class Broadcaster {

           @In("entityManager") EntityManager em;

           public String broadcast() {
                String sql =
                     "insert into Player_Announcment_assn " +
                     "  (player_id, announcement_id) " +
                     "  values (1, 1)";
                em.createNativeQuery(sql)
                     .executeUpdate();  // <-- line 36
                return "broadcast";
           }

      }

      ---

      javax.persistence.TransactionRequiredException: Executing an update/delete query
           at org.hibernate.ejb.QueryImpl.executeUpdate(QueryImpl.java:47)
           at com.thisispop.fuse.yci.session.Broadcaster.broadcast(Broadcaster.java:36)
           at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
           at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
           at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:46)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.persistence.ManagedEntityIdentityInterceptor.aroundInvoke(ManagedEntityIdentityInterceptor.java:48)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
           at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:166)
           at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:102)
           at com.thisispop.fuse.yci.session.Broadcaster_$$_javassist_7.broadcast(Broadcaster_$$_javassist_7.java)
           at com.thisispop.fuse.yci.test.AnnouncementTest$2.testComponents(AnnouncementTest.java:80)
           at org.jboss.seam.mock.BaseSeamTest$ComponentTest.run(BaseSeamTest.java:169)
           at com.thisispop.fuse.yci.test.AnnouncementTest.broadcast(AnnouncementTest.java:97)
      ... Removed 26 stack frames