[英]error when the method create an object (persisted entitiy)
我正在用eclipse和GWT在Java中编写一个汽车租赁代理商的Web应用程序,但是我陷入了该服务器方法的错误,该方法被失败的RPC使用的createRentDTO :
private RentDTO createRentDTO(Rent rent) {
return new RentDTO( createEmployeeDTO(rent.getEmployee()),
createClientDTO(rent.getClient()),
createCarDTO(rent.getCar()),
rent.getId() );
}
with the following , it works: 我注意到,如果我使用以下命令更改的 ,则它可以正常工作:
return new RentDTO(new EmployeeDTO("mike", "smith", (long) 99, "mike87","qwe123"),
new ClientDTO("harry", "jones", "cl24h89"),
new CarDTO("SUBARU", "supercar", (long) 25000,(long) 12),
rent.getId()
);
问题显然是我无法用“ harry”,“ jones”之类的随机值填充班级,但我必须采用已经保存的employee,client和car的值(我认为使用getter的租金,例如getEmployeeDTO .getClientDTo .getCarDTo吗?)。
以下是与此问题相关的其他代码: Rent.class
public class Rent implements Serializable {
Employee employee;
Client client;
Car car;
long id;
// getter and setter like:
public Employee getEmployee() {
return employee;
}
// getCar() and getClient are equal to getEmployee [...]
}
and are all simple classes (they are serialized to make them savable in the database ) very similar to each others, with some attributes like name ,surname ,username, password, id or price. 和都是简单的类(它们被序列化以使其可在数据库中保存)彼此非常相似,具有一些属性,例如名称,姓,用户名,密码,ID或价格。
我只写Employee.class
public class Employee {
String name;
String surname;
@Id
Long id;
String username;
String password;
// + getter and setter like getName() , getSurname() .....
}
这是方法createEmployeeDTO() :
(createCarDTO和createClientDTO等于...唯一改变的是一些属性)
private EmployeeDTO createEmployeeDTO(Employee employee) {
return new EmployeeDTO(employee.getName(),
employee.getSurname(),
employee.getId(),
employee.getUsername(),
employee.getPassword() );
}
is to make the user of the web application able to select which have rented a to a 的目的是使Web应用程序的用户能够选择哪个向租了
当RPC失败时,会出现一般错误
“ 500服务器上的呼叫失败;有关详细信息,请参阅服务器日志”
但是码头的服务器日志只说POST方法失败,并且在eclipse控制台中没有错误。
谢谢您的帮助,随时询问一切
您的DTO的构造函数的参数是否为零? 可见性不重要? 没有零参数构造函数,您的调用将失败。
您的DTO是否在共享软件包中? 如果要在服务器和客户端上使用DTO,则它们必须位于共享软件包中。
将日志级别更改为TRACE,以获取服务器日志中的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.