- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试插入数据库。我在下面发布我的代码。
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/
说真的,你怎么能在不发疯的情况下处理所有这些异常呢?我是不是读了太多关于异常处理的文章或什么?我尝试重构了几次,但每次似乎都以更糟糕的结果告终。也许我应该承认确实会发生异常(exception)情况,
背景 两者 try/rescue和 try/catch是 Elixir 中的错误处理技术。根据 corresponding chapter在介绍指南中。 Errors can be rescued u
每当我尝试在 Raspberry PI 上运行此 python 脚本时,我都会遇到问题: import socket import sys # Create a TCP/IP socket sock
我想知道一些关于 PHP 的 try , catch声明。 让我们考虑以下示例。 abstract class ExceptionA extends Exception {} class Except
我的 laravel v5.4 项目中有两个模型,user 和 admin。 在 config/auth.php 中,我向守卫和提供者添加了管理员,如下所示: 'guards' => [ 'w
try: r = requests.get(url, params={'s': thing}) except requests.ConnectionError, e: print e
我有以下代码。 但是,它并不能捕获所有错误,而我仍然会收到“throw er;//未处理的'错误'事件”。 为什么是这样? app.post('/api/properties/zip/:zip/bed
问题与细节 我正在使用自定义错误处理,遇到的错误之一是“路径中的非法字符”。我有一个自定义函数,旨在通过路径字符串查找此类非法字符,并在找到它们时引发自定义错误。但是我发现,取决于非法字符,Test-
This question already has answers here: How do I catch a numpy warning like it's an exception (not j
我正在使用其他人的代码,但我不熟悉try/catch,因此我举了一个类似的小例子。在第11行上,如果我写了error(''),似乎没有发现错误并增加了索引j。但是,编写error(' ')或error
我在我的一个程序中遇到了这个问题,在这种情况下,尝试/异常(exception)的错误使程序变得更好,以防用户意外输入了他们不应该输入的内容。它仍然给我错误,我为为什么感到困惑。如果对我的问题确实很重
我在尝试TRY ... CATCH块时遇到问题。有人可以解释为什么以下代码无法执行我的sp吗? DECLARE @Result int SET @Result = 0 BEGIN TRY SE
我有一个相当大的 powershell 脚本,其中包含许多(20 多个)执行各种操作的函数。 现在所有代码实际上都没有任何错误处理或重试功能。如果某个特定的任务/功能失败,它就会失败并继续。 我想改进
为什么我尝试时需要导入 inputmismatchException catch(InputMismatchException e){ System.out.println("
我对此感到困惑 - 我为辅助方法编写了一个 try/catch 。它的目的是捕获任何无效输入(任何不是“男性”或“女性”的内容(没有特定情况)。如果输入无效,它将通知用户,然后让他们重试。如果有效,则
我有时会发现自己处于如下场景。尽可能简单地陈述问题 “有时我会创建一段代码,Java 让我将其包含在 try/catch 语句中。我没有使用 catch,所以我将其留空。为什么这是错误的?” boo
我有点困惑为什么当我不使用 Try block 时会出现 Try block 错误。 我在代码块底部附近收到错误通知。如果我不使用 try/catch,有人可以向我解释为什么会发生这种情况吗? 它是否
我已经盯着我的电脑两个小时了,我不知道我做错了什么。谁能帮助我看到光明? package blackjack; import java.util.Random; import java.util.Sc
我想将方法保存在 Enum 中,但 Class.getDeclaredMethod 抛出 NoSuchMethodException,那么我该如何处理呢?我的代码: public enum Car
这个问题已经有答案了: Executing multi-line statements in the one-line command-line (18 个回答) 已关闭 3 年前。 如何使用try.
我是一名优秀的程序员,十分优秀!