2012-01-22 5 views
0

今日は、プレゼンテーションレイヤーとしてGWTを使用する必要があるアプリケーションを強制します。私は私のプロジェクトを処理するのに役立ついくつかのことを学んだが、今は問題解決のために良い解決策を見つけることができない。私は私が送りたい言及する必要がありgWtを使ってオブジェクトを送信する

com.google.gwt.user.client.rpc.SerializationException: Type 'org.hibernate.collection.PersistentBag' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.: instance = [[email protected], [email protected], [email protected]] 

問題は、私は私が春のOのプレゼンテーション層(GWT)で休止状態でMySQLから取得したオブジェクトを送信しようとすると、私はこの例外を取得するということですExamという名前のクラスで、このクラスには質問クラスのリストがあります。

私はこの問題を取り除くために少しでも助けてくれて本当に感謝しています。

答えて

1

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

0

はあなたjoin fetchが試験でリストを編あり、私は唯一のDTOは、GWTのクライアント側に転送することができ引き起こし、あなたはデータ転送オブジェクトを使用する必要があり、それが初期化されていない怠惰なコレクションだと思う(人口)まだ

+0

yes.iはEAGERフェッチを使用し、ここであなたのエラーに関するいくつかの情報を見つけることができます – Sina

関連する問題