。
ExamDtoとQuestionDtoを作成し、ExamオブジェクトをExamDtoに変換しなければなりません。
クライアント側では、DTOのみを操作します。 ExamをMySQLに保存したい場合は、ExamDtoをExamに変換する必要があります。
POJOをDTOに変換して戻すには、Dozerを使用してください。
Dozerを使用するには、Dozerマッピングを使用してDTOとPOJOをマッピングする必要があります。私はCustom Mappings Via Dozer XML Filesを使用します。 GWT-Hibernateの関係を説明し
最高のチュートリアル:Using GWT with Hibernate
はまた、I'vは、コンバータクラスDozerGeneratorを作成し、自分のアプリケーションでそれを使用しています。たとえば、私は2つのRPCを持っています - 1つはユーザを見つけること、もう1つはユーザを保存することです。
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;
}
}
はまた、私はspring4gwtとギリアド(hibernate4gwt)などの特別なライブラリをせずに自分のアプリケーションでGWT +春+ JPA + Hibernateはを使用して、それが正常に動作します。
またIssue 3296
yes.iはEAGERフェッチを使用し、ここであなたのエラーに関するいくつかの情報を見つけることができます – Sina