当前位置: 首页 > 知识库问答 >
问题:

JBoss Seam+jsf javax.ejb.EJBTransactionRolledBackException“

颜昕
2023-03-14

我对JSF很陌生,我先尝试了一个crud操作来继续我的项目,但是我在将数据插入到表中的时候遇到了一个问题。希望有人能对我的错误开刀。我从控制台上的错误报告开始,然后是类。

我的堆栈跟踪如下:

            Exception during request processing:
            Caused by javax.ejb.EJBTransactionRolledbackException with message: ""
            org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:87)
            org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:210)
            org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:84)
            $Proxy256.saveOrUpdate(Unknown Source)
            org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
            org.javassist.tmp.java.lang.Object_$$_javassist_seam_21.saveOrUpdate(Object_$$_javassist_seam_21.java)
            com.ermms.clrp.loginhistory.LoginhistoryActionImpl.create(LoginhistoryActionImpl.java:47)
            sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:84)
            $Proxy165.create(Unknown Source)
            sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
            org.primefaces.application.CleanupActionListener.processAction(CleanupActionListener.java:42)
            org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
            org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
            org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
            org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
            org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
            java.lang.Thread.run(Thread.java:662)
            Caused by java.lang.NullPointerException with message: ""
            com.ermms.clrp.dto.loginhistory.LoginhistoryMapper.mapLoginhistoryEntity(LoginhistoryMapper.java:17)
            com.ermms.clrp.service.loginhistory.LoginhistoryServiceImpl.saveOrUpdate(LoginhistoryServiceImpl.java:35)
            sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            java.lang.reflect.Method.invoke(Method.java:597)
            sun.reflect.GeneratedMethodAccessor84.invoke(Unknown Source)
            sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            java.lang.reflect.Method.invoke(Method.java:597)
            org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
            org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
            org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
            org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:240)
            org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:210)
            org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:84)
            $Proxy256.saveOrUpdate(Unknown Source)
            sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            java.lang.reflect.Method.invoke(Method.java:597)
            org.javassist.tmp.java.lang.Object_$$_javassist_seam_21.saveOrUpdate(Object_$$_javassist_seam_21.java)
            com.ermms.clrp.loginhistory.LoginhistoryActionImpl.create(LoginhistoryActionImpl.java:47)
            sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            java.lang.reflect.Method.invoke(Method.java:597)
            sun.reflect.GeneratedMethodAccessor84.invoke(Unknown Source)
            sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            $Proxy165.create(Unknown Source)
            org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
            java.lang.Thread.run(Thread.java:662)

我用于插入日期的xhtml页面:

            <ui:define name="main-container">
                <div class="panel-content">
                    <h:form class="input-list" id="creatuser" style="width:100%;">
                        <h:panelGrid border="1" class="creatUserDetailsTable">
                            <f:facet name="header">
                                <h:outputText value="User Login History"
                                    style="font-size: 23px; font-weight: bold; color: threeddarkshadow;" />
                            </f:facet>
                            <s:decorate id="nameDec" template="../../../secure/edit.xhtml">
                                <ui:define name="label">Name:</ui:define>
                                <h:inputText tabindex="1" id="amount" type="text"
                                    class="miniusername clp"
                                    value="#{loginhistoryAction.currentLoginhistory.name}" required="true">
                                    <f:validateLength minimum="3" maximum="20" />
                                </h:inputText>
                            </s:decorate>
                        </h:panelGrid>
                        <h:commandButton value="Save" tabindex="20" class="usersubmit"
                            action="#{loginhistoryAction.create}">
                        </h:commandButton>
                    </h:form>
                    <h:messages globalOnly="true" />
                </div>
            </ui:define>

使用的接口:@Local public Interface LoginhistoryAction extends Serializable{public String create();public String initCurrentLoginhistory();public void setCurrentLoginhistory(Loginhistory currentLoginhistory);public Loginhistory getCurrentLoginhistory();}

action类实现了上述接口:@Name(“LoginhistoryAction”)@Stateless@AutoCreate公共类LoginhistoryActionImpl实现了LoginhistoryAction{@Out(值=“CurrentLoginHistory”,scope=ScopeType.Conversation)@In(值=“CurrentLoginHistory”,scope=ScopeType.Conversation,required=false)private Loginhistory CurrentLoginHistory;

                public Loginhistory getCurrentLoginhistory() {
                    return currentLoginhistory;
                }

                public void setCurrentLoginhistory(Loginhistory currentLoginhistory) {
                    this.currentLoginhistory = currentLoginhistory;
                }

                @In
                private LoginhistoryService LoginhistoryService;

                private static final long serialVersionUID = 8282995226262125676L;

                public String create() {
                    currentLoginhistory.setRef("Test");
                    Integer id = LoginhistoryService.saveOrUpdate(this.currentLoginhistory);
                    return "/secure/userhome.xhtml";
                }

                @Override
                public String initCurrentLoginhistory() {
                    currentLoginhistory = new Loginhistory();
                    return "/secure/common/history/loginHistory.xhtml";
                }
            }

服务接口:@local public interface LoginhistoryService extends Serializable{public abstract Integer saveOrUpdate(Loginhistory Loginhistory);}

ServiceImpl类:

            @Name("LoginhistoryService")
            @Stateless
            @AutoCreate
            public class LoginhistoryServiceImpl implements LoginhistoryService {

                private static final long serialVersionUID = 1L;
                @In
                private LoginhistoryDAO loginhistoryDAO;

                public LoginhistoryServiceImpl() {
                    super();
                }

                @Override
                // TODO what to do with lastmodified if it is modify
                public Integer saveOrUpdate(Loginhistory loginhistory) {
                    LoginhistoryEntity loginhistoryEntity = LoginhistoryMapper.mapLoginhistoryEntity(loginhistory);
                    Integer loginhistoryId = loginhistoryDAO.saveOrUpdate(loginhistoryEntity);
                    return loginhistoryId;
                }
            }

映射器类:公共类LoginhistoryMapper{

                public static LoginhistoryEntity mapLoginhistoryEntity(
                        Loginhistory loginhistory) {
                    LoginhistoryEntity loginhistoryEntity = new LoginhistoryEntity();
                    loginhistoryEntity.setId(loginhistory.getId());
                    loginhistoryEntity.setName(loginhistory.getName());
                    loginhistoryEntity.setDate(loginhistory.getDate());
                    return loginhistoryEntity;
                }

            }
            @Name("loginhistoryDAO")
            @Stateless
            @AutoCreate
            public class JPALoginhistoryDaoImpl implements LoginhistoryDAO {

                private static final long serialVersionUID = -6173881454668735683L;

                @PersistenceContext(unitName = "clrp")
                private EntityManager entityManager;

                Logger logger = Logger.getLogger(this.getClass());
                public void setEntityManager(EntityManager em) {
                    this.entityManager = em;
                }

                @Override
                public Integer saveOrUpdate(LoginhistoryEntity newLoginhistory) {
                    entityManager.merge(newLoginhistory);
                    return newLoginhistory.getId();
                }

            }

我的实体如下:

            @Entity
            @Table(name="loginhistory")
            @NamedQueries(value = {
                    @NamedQuery(name = LoginhistoryEntity.fetchAll, query = "FROM LoginhistoryEntity" )})

            public class LoginhistoryEntity implements Serializable {
                private static final long serialVersionUID = 1L;
                public final static String fetchAll = "LoginhistoryEntity.fetchAll";

                @Id
                @GeneratedValue(strategy = GenerationType.IDENTITY)
                @Column(name = "id", updatable = false)
                private int id;

                @Column(name = "Date")
                private Date date;

                @Column(name = "Name")
                private String name;

                @Column(name = "Ref")
                private String ref;

                public int getId() {
                    return this.id;
                }

                public void setId(int id) {
                    this.id = id;
                }


                public String getName() {
                    return this.name;
                }

                public void setName(String name) {
                    this.name = name;
                }

                public void setDate(Date date) {
                    this.date = date;
                }

                public Date getDate() {
                    return date;
                }

                public void setRef(String ref) {
                    this.ref = ref;
                }

                public String getRef() {
                    return ref;
                }

            }

共有1个答案

樊胜
2023-03-14

最后,我发现了错误,一个微不足道的错误,对不起你在这里的时间…

我的实体以前是

            @Id
            @GeneratedValue(strategy = GenerationType.IDENTITY)
            @Column(name = "historyId", updatable = false)
            private Integer historyId;

这里的问题是整数类型,它应该是

            @Id
            @GeneratedValue(strategy = GenerationType.IDENTITY)
            @Column(name = "id", updatable = false)
            private Integer id;

干杯

 类似资料:

相关问答

相关文章

相关阅读