gpt4 book ai didi

java - 错误 :java. lang.IllegalArgumentException:尝试使用空实体创建 saveOrUpdate 事件

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:14:36 26 4
gpt4 key购买 nike

我正在尝试插入数据库。我在下面发布我的代码。

DAO 类:

package com.persistent.progracers.data.dao;    

import org.hibernate.Session;
import com.persistent.progracers.data.pojo.UserDemographicInfo;

public class UserDemographicInfoDAO {
public void persist(UserDemographicInfo userDemographicInfo, Session session){
session.save("UserDemographicInfo", userDemographicInfo);
}

public void update(UserDemographicInfo userDemographicInfo, Session session){
session.saveOrUpdate("UserDemographicInfo", userDemographicInfo);
}

public void delete(UserDemographicInfo userDemographicInfo, Session session){
session.delete("UserDemographicInfo", userDemographicInfo);
}

}

POJO 类:

 package com.persistent.progracers.data.pojo;

import java.util.Date;

@SuppressWarnings("serial")
public class UserDemographicInfo implements java.io.Serializable {

private long id;
private String firstName;
private String lastName;
private Date dateOfBirth;
private String mobileNumber;
private String gender;
private String status;
private Address address;
private String employeeID;
private String bloodGroup;
private Date dateCreated;
private Date dateModified;

public UserDemographicInfo() {
}

public UserDemographicInfo(String firstName, String lastName,
Date dateOfBirth, String mobileNumber, String gender,
String status, Address address, String employeeID,
String bloodGroup, Date dateCreated, Date dateModified) {
this.firstName = firstName;
this.lastName = lastName;
this.dateOfBirth = dateOfBirth;
this.mobileNumber = mobileNumber;
this.gender = gender;
this.status = status;
this.address = address;
this.employeeID = employeeID;
this.bloodGroup = bloodGroup;
this.dateCreated = dateCreated;
this.dateModified = dateModified;
}

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

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

public String getFirstName() {
return this.firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return this.lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public Date getDateOfBirth() {
return this.dateOfBirth;
}

public void setDateOfBirth(Date dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}

public String getMobileNumber() {
return this.mobileNumber;
}

public void setMobileNumber(String mobileNumber) {
this.mobileNumber = mobileNumber;
}

public String getGender() {
return this.gender;
}

public void setGender(String gender) {
this.gender = gender;
}

public String getStatus() {
return this.status;
}

public void setStatus(String status) {
this.status = status;
}

public Address getAddress() {
return this.address;
}

public void setAddress(Address address) {
this.address = address;
}

public String getEmployeeID() {
return this.employeeID;
}

public void setEmployeeID(String employeeID) {
this.employeeID = employeeID;
}

public String getBloodGroup() {
return this.bloodGroup;
}

public void setBloodGroup(String bloodGroup) {
this.bloodGroup = bloodGroup;
}

public Date getDateCreated() {
return this.dateCreated;
}

public void setDateCreated(Date dateCreated) {
this.dateCreated = dateCreated;
}

public Date getDateModified() {
return this.dateModified;
}

public void setDateModified(Date dateModified) {
this.dateModified = dateModified;
}

}

hibernate .cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="SessionFactory">
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">admin123</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/ngo</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.default_schema">ngo</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="current_session_context_class">thread</property>
<mapping resource="com/persistent/progracers/data/pojo/UserDemographicInfo.hbm.xml"/>

现在的问题是我正在使用 WaveMaker Studio..它创建了一个 Java 服务。所以 Java 服务代码在这里:

import org.hibernate.Session;

import com.persistent.progracers.data.dao.UserDemographicInfoDAO;
import com.persistent.progracers.data.pojo.UserDemographicInfo;
import com.persistent.progracers.wecare.factory.HibernateSessionFactory;


public class UserRegistrationService extends com.wavemaker.runtime.javaservice.JavaServiceSuperClass {
/* Pass in one of FATAL, ERROR, WARN, INFO and DEBUG to modify your log level;
* recommend changing this to FATAL or ERROR before deploying. For info on these levels, look for tomcat/log4j documentation
*/
public UserRegistrationService() {
super(INFO);
}

public UserDemographicInfo sampleJavaOperation(UserDemographicInfo demopojo) {
UserDemographicInfoDAO demodao=new UserDemographicInfoDAO();

Session session = HibernateSessionFactory.getSession();
try {
log(INFO, "Starting sample operation");
demodao.persist(demopojo, session);
log(INFO, "Returning ");
} catch(Exception e) {
log(ERROR, "The sample java service operation has failed", e);
}
return demopojo;
}

}

wavemaker 中有一个服务变量,它将所有值绑定(bind)到表的相关字段。但是当我单击保存按钮时它给我错误

:java.lang.IllegalArgumentException: attempt to create saveOrUpdate event with null entity.

堆栈跟踪:

INFO (JavaServiceSuperClass.java:155) 22:41:25 - Starting sample operation
ERROR (JavaServiceSuperClass.java:131) 22:41:26 - The sample java service operation has failed
java.lang.IllegalArgumentException: attempt to create saveOrUpdate event with null entity
at org.hibernate.event.SaveOrUpdateEvent.(SaveOrUpdateEvent.java:40)
at org.hibernate.event.SaveOrUpdateEvent.(SaveOrUpdateEvent.java:23)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
at com.persistent.progracers.data.dao.UserDemographicInfoDAO.persist(UserDemographicInfoDAO.java:8)
at UserRegistrationService.sampleJavaOperation(UserRegistrationService.java:32)
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:597)
at com.wavemaker.runtime.service.reflect.ReflectServiceType.invokeMethod(ReflectServiceType.java:122)
at com.wavemaker.runtime.server.ServerUtils.invokeMethodWithEvents(ServerUtils.java:303)
at com.wavemaker.runtime.server.ControllerBase.invokeMethod(ControllerBase.java:269)
at com.wavemaker.runtime.server.JSONRPCController.executeRequest(JSONRPCController.java:123)
at com.wavemaker.runtime.server.ControllerBase.handleRequestInternal(ControllerBase.java:125)
at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.jav a:153)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:788)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:717)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:143)
at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:98)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

谁能告诉我这里有什么错误?

最佳答案

这里,

 public UserDemographicInfo sampleJavaOperation(UserDemographicInfo demopojo) {
UserDemographicInfoDAO demodao=new UserDemographicInfoDAO();

这里

demodao.persist(demopojo, session);

UserDemographicInfo demopojo 为空。

该代码调用:

public void persist(UserDemographicInfo userDemographicInfo, Session session){
session.save("UserDemographicInfo", userDemographicInfo);
}

并抛出错误。

关于java - 错误 :java. lang.IllegalArgumentException:尝试使用空实体创建 saveOrUpdate 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8975031/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com