您应该使用数据传输对象,仅使DTO的可转移到GWT客户端。
您应该创建ExamDto和QuestionDto,并且在从MySQL接收到考试对象后,您必须将其转换为ExamDto。
在客户端,您将只使用DTO。如果您想将考试保存到MySQL,您应该将ExamDto转换为考试。
要将POJO转换为DTO并返回,应使用Dozer。
要使用推土机,您需要使用推土机映射来映射DTO和POJO。我使用Custom Mappings Via Dozer XML Files。
描述GWT-Hibernate的关系最好的教程:Using GWT with Hibernate
而且,我心中已经创建转换器类DozerGenerator,在我的应用程序中使用它。例如,我有2个RPC--其中一个是查找用户,其次是保存用户。
public UserDto findUserById(long id) throws IllegalArgumentException {
//userService.findUserById(long id) returns User object and than
//you need to convert it to UserDto to transfer to client.
return DozerGenerator.appUserEntityToDto(userService.findUserByID(id));
}
//here, you converts UserDto to User
public Long saveUser(UserDto userDto) throws IllegalArgumentException {
return userService.saveUser(DozerGenerator.appUserDtoToEntity(mapper, userDto));
}
在这里,它的DozerGenerator类:
public class DozerGenerator {
/* User <-> UserDto */
public static User appUserDtoToEntity(DozerBeanMapper mapper, UserDto dto) {
return mapper.map(dto, User.class);
}
public static UserDto appUserEntityToDto(DozerBeanMapper mapper, User user) {
return mapper.map(user, UserDto.class);
}
public static List<UserDto> appUserListEntityToDto(DozerBeanMapper mapper, List<User> users) {
List<UserDto> models = new ArrayList<UserDto>();
for (User u : users) {
models.add(DozerGenerator.appUserEntityToDto(mapper, u));
}
return models;
}
public static List<User> appUserListDtoToEntity(DozerBeanMapper mapper, List<UserDto> dtos) {
List<User> users = new ArrayList<User>();
for (UserDto u : dtos) {
users.add(DozerGenerator.appUserDtoToEntity(mapper, u));
}
return users;
}
}
另外,我使用GWT +春+ JPA + Hibernate的我的应用程序不需要任何特殊的库,spring4gwt和吉利德(hibernate4gwt),它工作正常。
您还可以在此处找到有关Issue 3296
好啊。你的错误的一些信息使用EAGER取 – Sina