[JBoss Seam] - End conversation context
by ebu
Hi,
I can't understand why conversation context is not deleted when method annotated as @End is being called. Here is the code:
| @Stateful
| @Name("editSomething")
| public class EditSomething implements EditSomethingLocal {
| @PersistenceContext
| EntityManager em;
|
| @Resource
| SessionContext ctx;
|
| @In
| Context sessionContext;
|
| @In(create=true)
| @Out
| Something something;
|
| @In(create=true)
| FacesMessages facesMessages;
|
| @Begin(join=true)
| public void prepare(){
| System.out.println("prepare");
| }
|
| @End(beforeRedirect=true)
| public void create(){
| em.persist(something);
| }
|
| @Remove
| @Destroy
| public void remove(){
|
| }
| }
|
form to create:
| <h:form>
| <table border="0">
| <tr>
| <td class="cntForm">Name</td>
| <td class="cntForm">
| <h:inputText id="name" required="true" value="#{something.name}">
| <s:validate />
| </h:inputText> *
| </td>
| <td><h:message for="name" styleClass="cntError" /></td>
| </tr>
| </table>
|
| <h:commandButton action="#{editSomething.create}" value="Create" />
| </h:form>
|
|
The first entity is created ok, but when then the form is displayed the input field contains name of the created item, and when Create button pushed secnod time i'm getting
| javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist
|
that's clear - since context was not destroyed the entity stored in it got detached and when again was passesed to persist causes exception. But according to seam docs
anonymous wrote :
| When an @End method is encountered, any long-running conversation context is demoted to a temporary conversation
|
and
anonymous wrote :
| At the end of the restore view phase of the JSF request lifecycle, Seam attempts to restore any previous long-running conversation context. If none exists, Seam creates a new temporary conversation context.
|
Thus, if existing contex was demoted to temporary one seam should create new temporary conversation context (and create new Something in it!) which in it's turn should be promoted to the long running conversation when prepare() is called...
What do i miss?
wbr, eugen.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3998610#3998610
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3998610
19 years, 3 months
[JBoss Seam] - Catching persistence exceptions within component methods
by fernando_jmt
I have the following code that performs the creation of one User entity:
|
| @Stateful
| @Name("userManager")
| @Scope(ScopeType.EVENT)
| public class UserManagerAction implements UserManager {
|
| @In
| private User user;
|
| @PersistenceContext
| private EntityManager em;
|
| public String create() {
| try {
| em.persist(user);
|
| } catch(EntityExistsException e) {
| facesMessages.add("Username already exists");
| return Outcome.REDISPLAY;
| }
|
| }
|
|
In the above code, when the create method was executed, then the EntityExistsException was never caught. I only got a full stacktrace error in the console, and of course the message is not displayed.
After trying for a while to found the reason for this behaviour, I remember some issue I had when saving and trying to catch exceptions in a DAO using spring and Hibernate. The solution for this was execute the flush() method after every entity interaction. Then I added the line to the above code, and I had:
| @Stateful
| @Name("userManager")
| @Scope(ScopeType.EVENT)
| public class UserManagerAction implements UserManager {
|
| @In
| private User user;
|
| @PersistenceContext
| private EntityManager em;
|
| public String create() {
| try {
| em.persist(user);
| em.flush();
| } catch(EntityExistsException e) {
| facesMessages.add("Username already exists");
| return Outcome.REDISPLAY;
| }
|
| }
|
|
After adding the em.flush() line , EntityExistsException was caught, the message added and the outcome correctly invoked. But in the console I still have the stacktrace:
| Hibernate: insert into users (password, firstname, lastname, email, version, country, city, province, street, enabled, accountexpired, accountlocked, credentialsexpired, username) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
| 18:36:46,823 WARN [JDBCExceptionReporter] SQL Error: 1062, SQLState: 23000
| 18:36:46,823 ERROR [JDBCExceptionReporter] Duplicate entry 'fer' for key 1
| 18:36:46,823 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
| org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
| at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
| at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
| at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249)
| at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
| at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
| at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
| at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
| at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:993)
| at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:267)
| at org.jboss.ejb3.entity.TransactionScopedEntityManager.flush(TransactionScopedEntityManager.java:204)
| at com.jatun.jrbundler.action.UserManagerAction.create(UserManagerAction.java:55)
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
| at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
| at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:37)
| at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:55)
| at org.jboss.seam.interceptors.BijectionInterceptor.bijectTargetComponent(BijectionInterceptor.java:51)
| at sun.reflect.GeneratedMethodAccessor70.invoke(Unknown Source)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
| at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:169)
| at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:64)
| at org.jboss.seam.interceptors.OutcomeInterceptor.interceptOutcome(OutcomeInterceptor.java:23)
| at sun.reflect.GeneratedMethodAccessor69.invoke(Unknown Source)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
| at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:169)
| at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:64)
| at org.jboss.seam.interceptors.ConversationInterceptor.endOrBeginLongRunningConversation(ConversationInterceptor.java:51)
| at sun.reflect.GeneratedMethodAccessor68.invoke(Unknown Source)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
| at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:169)
| at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:64)
| at org.jboss.seam.intercept.RootInterceptor.createSeamInvocationContext(RootInterceptor.java:144)
| at org.jboss.seam.intercept.RootInterceptor.invokeInContexts(RootInterceptor.java:129)
| at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:102)
| at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:49)
| at sun.reflect.GeneratedMethodAccessor67.invoke(Unknown Source)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
| at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:57)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
| at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:201)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:81)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.stateful.StatefulContainer.localInvoke(StatefulContainer.java:189)
| at org.jboss.ejb3.stateful.StatefulLocalProxy.invoke(StatefulLocalProxy.java:98)
| at $Proxy51.create(Unknown Source)
| at com.jatun.jrbundler.action.UserManager$$FastClassByCGLIB$$9d570455.invoke(<generated>)
| at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
| at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:45)
| at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:73)
| at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:55)
| at org.jboss.seam.interceptors.RemoveInterceptor.removeIfNecessary(RemoveInterceptor.java:39)
| at sun.reflect.GeneratedMethodAccessor72.invoke(Unknown Source)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
| at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:169)
| at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:64)
| at org.jboss.seam.interceptors.ExceptionInterceptor.handleExceptions(ExceptionInterceptor.java:38)
| at sun.reflect.GeneratedMethodAccessor66.invoke(Unknown Source)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
| at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:169)
| at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:64)
| at org.jboss.seam.intercept.RootInterceptor.createSeamInvocationContext(RootInterceptor.java:144)
| at org.jboss.seam.intercept.RootInterceptor.invokeInContexts(RootInterceptor.java:129)
| at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:102)
| at org.jboss.seam.intercept.ClientSideInterceptor.interceptInvocation(ClientSideInterceptor.java:82)
| at org.jboss.seam.intercept.ClientSideInterceptor.intercept(ClientSideInterceptor.java:51)
| at com.jatun.jrbundler.action.UserManager$$EnhancerByCGLIB$$e4d9e3d0.create(<generated>)
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at com.sun.el.parser.AstValue.invoke(AstValue.java:151)
| at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:283)
| at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
| at com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBinding.java:69)
| at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)
| at javax.faces.component.UICommand.broadcast(UICommand.java:106)
| at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:94)
| at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:168)
| at org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:343)
| at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:86)
| at com.icesoft.faces.webapp.xmlhttp.BlockingServlet.renderCycle(BlockingServlet.java:435)
| at com.icesoft.faces.webapp.xmlhttp.BlockingServlet.receiveUpdates(BlockingServlet.java:423)
| at com.icesoft.faces.webapp.xmlhttp.BlockingServlet.service(BlockingServlet.java:277)
| at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
| at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
| at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
| at org.jboss.seam.servlet.SeamExceptionFilter.doFilter(SeamExceptionFilter.java:46)
| at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
| at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
| at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
| at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
| at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
| at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
| at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
| at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
| at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
| at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
| at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
| at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
| at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
| at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
| at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
| at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
| at java.lang.Thread.run(Thread.java:595)
| Caused by: java.sql.BatchUpdateException: Duplicate entry 'fer' for key 1
| at com.mysql.jdbc.ServerPreparedStatement.executeBatch(ServerPreparedStatement.java:652)
| at org.jboss.resource.adapter.jdbc.WrappedStatement.executeBatch(WrappedStatement.java:517)
| at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
| at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
| ... 132 more
|
|
Is there some way this exception stacktrace don't be thrown?
By the way. In the example code I wrote above, should I use the sessionContext.setRollbackOnly() every time I catch persistence exceptions?
will the transaction rollback even when I catch the exception like I did (for the example it seem it works)?
Any help will be appreciated a lot.
Tkanks in advance.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3998608#3998608
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3998608
19 years, 3 months
[Installation, Configuration & Deployment] - mysql connection refused
by rgjawanda
I have jboss 4.0.2 running on my ubuntu linux server.
I have 5.0.1 mysql and the 3.0.1 mysql-connector
My datasource gets registered ad MySqlDSL
and in the jmx console it says bind name
java:MySqlDSL
So far so good.
I my war application (i connect using ) this
Statement stmt =null ;
ResultSet rs = null;
boolean test = false ;
try {
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:/MySqlDSL");
con = ds.getConnection();
con.setAutoCommit(false);
con.setTransactionIsolation(con.TRANSACTION_SERIALIZABLE) ;
stmt = con.createStatement();
StringBuffer sb = new StringBuffer() ;
sb.setLength(0) ;
Jboss throws and exception
JbossManagedConnectionPool throwable while attempting to get a new connection: null
communications lik failure du to underlying exception
java.net.ConnectException Connection refused
my connection-url string is
<connection-url>jdbc:mysql://localhost:3305/tracker
my username and password are correct.
I try this on the command line and I can login.
Any idea?
Thanks a million if you answer.
Ron
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3998558#3998558
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3998558
19 years, 3 months