0
votes

I am very new to JSF and I tried a crud operation first to proceed the further in my project.But I have a struck up here, while inserting data into table.Also spend lot of time in this, but cant get out from this. Hope some one could shoot my mistake. I am starting from my error report on console and followed by the classes.

My stack trace as follows:

            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)

The xhtml page I used for insert the date:

            <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>

Interface used : @Local public interface LoginhistoryAction extends Serializable { public String create(); public String initCurrentLoginhistory(); public void setCurrentLoginhistory(Loginhistory currentLoginhistory); public Loginhistory getCurrentLoginhistory(); }

The action class implements the above interface: @Name("loginhistoryAction") @Stateless @AutoCreate public class LoginhistoryActionImpl implements LoginhistoryAction { @Out(value = "currentLoginhistory", scope = ScopeType.CONVERSATION) @In(value = "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";
                }
            }

Service interface: @Local public interface LoginhistoryService extends Serializable { public abstract Integer saveOrUpdate(Loginhistory Loginhistory); }

ServiceImpl class:

            @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;
                }
            }

Mapper class: public class 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;
                }

            }

DAO interface: @Local public interface LoginhistoryDAO extends Serializable { public Integer saveOrUpdate(LoginhistoryEntity newLoginhistory); }

JPAclassDAOImpl class:

            @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();
                }

            }

My entity is as follows:

            @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

1 Answers

0
votes

Finally I found the mistake, trivial one and sorry for your time here..

My entity was previously

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

Problem here the integer type, it should be

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

Cheers