views:

48

answers:

3

Hi, When using Persistence frameworks like Hibernate, JPA etc. on the server side, what are the general practices of passing on the data between client and server ? Are there any existing design patterns for the same ?

Thanks.

+1  A: 

Client-server, or with the inclusion of database, 3-tier architecture is a design pattern itself. The question is rather which technology should be used in the communication. There are many choices, e.g. HTTP, TCP, UDP, JMS, XMLRPC, RMI, CORBA, C RPC or flash-drives carried by post pigeons. In general, it is advised to

  • use a technology that has a tooling to define your message/data format, like SOAP (WSDL), CORBA (IDL), XML (XSD, Relax NG, Schematron,..) over JMS/HTTP/....
  • choose a text-based format (XML, JSON, ..) instead of a binary (RMI, CORBA, ..) when performance is not a major issue. Text formats are easier to understand for the programmers writing the next version or a brand new client. It is also easier to debug or audit such an interface.
  • use an open, standard technology, don't re-invent the wheel.
  • choose an underlying transport that suits your communication model. E.g. JMS is well suited for fire-and-forget communication, while HTTP is well suited for synchronous request-reply.
  • keep in mind higher-level architecture. E.g. if your server (service) is one of many maintained by the same IT department, it is advised to use the same communication technology for all of them (see also SOA).

Regarding your question on dependency on the chosen persistence framework, I think there is none. Your choice of using e.g. Hibernate does not enforce or exclude any client-server communication technologies.

Miklos
+1  A: 

Dunno about patterns but i know in a design using for exemple EJB3 with JPA that it's not recommended to pass JPA entities to client threw remote EJB's because proxies stay and it can generate a lot of useless network trafic. You'd better detach your entities or give to client simple value objects.

Sebastien Lorber
Hi, Are there any standard patterns/practices around creating value objects?
soontobeared
I think you should read that:http://forums.sun.com/thread.jspa?threadID=5302559Explains everything :)Use DTO Pattern :)
Sebastien Lorber
Also in JEE6 you can detach a single entity with the entity manager thus you can give a detached entity to the client without serializing everything i guess...Before that you had to detach all your entities in the same time... :(
Sebastien Lorber
A: 

Ideally, the persistence layer should be quite separate from your client-server comms layer. While not strictly a pattern, the idea here is loose coupling.

As HerQuLe said, you should try to make sure that the data you send between client and server is just POJO style info, rather than serializing a (possibly much more complex) proxy.

John