1

The hibernate POJO only allow list, which is an interface, to map many-to-one relationship.

public class Employee {
private int id;
private String firstName; 
private String lastName;   
private int salary;
private List certificates;

But GWT-RPC only allows concrete type, such as ArrayList, as the return. So, instead of defining a similar class with ArrayList only for RPC,

public class EmployeeRPC {
private int id;
private String firstName; 
private String lastName;   
private int salary;
private **ArrayList<Certificate>** certificates;

is there any other way to convert the hibernate POJO into a serializable object?

Thanks

Ming Leung
  • 385
  • 2
  • 13
  • You mean one-to-many relationship. Not related to your question, but unless you need a special ordering, it's better to use Set for a collection in JPA entities - Set performs better and you can fetch multiple Sets in one query (you cannot do it with Lists/Bags). – Ján Halaša Mar 05 '18 at 09:46
  • Thank you for your reply. But my point is about converting the hibernate POJO into GWT-RPC compatible object. – Ming Leung Mar 05 '18 at 09:48

1 Answers1

0

You can use List<Serializable> but the generated javascript will be bigger.

When passing objects across RPC call's its a good practice to declare concrete parameter types in the RPC interface. If for some reason you cannot use concrete class in the RPC interface try to be as specific as possible.
This is because the GWT compiler while emitting javascript has to take into account all possible variants of List in the compilation unit. This includes all the classes extending List and Serializable interface in the class path. The permutations can be huge, which will effect your compile time as well as the application download size.

Full answer here

Making a class serializable for GWT RPC:

A class is serializable if it meets these three requirements:
- It implements either Java Serializable or GWT IsSerializable interface, either directly, or because it derives from a superclass that does.
- Its non-final, non-transient instance fields are themselves serializable, and
- It has a default (zero argument) constructor with any access modifier (e.g. private Foo(){} will work)

Docu

You will have to add this stuff to your class... Also make sure that Certificate is serializable.

Or just use JSON: resty-gwt, gwt-jackson

Tobika
  • 1,037
  • 1
  • 9
  • 18
  • Thank you for your reply. Can List be passed over GWT RPC? The List by itself is not Serializable, but the ArrayList is. – Ming Leung Mar 06 '18 at 07:47