我是JSF的新手,我首先尝试了一个crud操作,以便在我的项目中继续进行。但是我在这里进行了一次攻击,同时将数据插入到table.Also中花了很多时间,但是无法离开由此。希望有人可以解决我的错误。我从控制台上的错误报告开始,然后是类。
我的堆栈跟踪如下:
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>
使用的界面: @本地 公共接口LoginhistoryAction extends Serializable { public String create(); public String initCurrentLoginhistory(); public void setCurrentLoginhistory(Loginhistory currentLoginhistory); public Loginhistory getCurrentLoginhistory(); }
动作类实现上面的接口: @name( “loginhistoryAction”) @Stateless @AutoCreate public class LoginhistoryActionImpl实现LoginhistoryAction { @Out(value =“currentLoginhistory”,scope = ScopeType.CONVERSATION) @In(value =“currentLoginhistory”,scope = ScopeType.CONVERSATION,required = false) 私人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";
}
}
服务界面: @本地 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;
}
}
Mapper类: 公共类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界面: @本地 公共接口LoginhistoryDAO扩展Serializable { public Integer saveOrUpdate(LoginhistoryEntity newLoginhistory); }
JPAclassDAOImpl类:
@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;
}
}
答案 0 :(得分:0)
最后,我发现了这个错误,琐碎的一个,对不起你在这里的时间..
我的实体以前是
@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;
干杯