0

can someone help me plz?

i am trying to get a synchronization between N "clients" database to 1 Big "Server" database (kind of repository/backup database). Its ok, i got a way to make their sync fine.

but, it was demanded the "Server" will be a "Client" application too, with same Java classes, models, entities, business, etc..

I am trying to find a solution to this Server database holds all database content from all Clients without making major changes to my entities (cause i will need to apply then on Client too)

This is an example of what i tried, but no success how to implement it on JPA and Serialization through EJB remotes.

@Entity
    @Table(name="crud_sync")
    public class CrudSync implements Serialization{
        private static final long serialVersionUID = 1L;
        @Id private Long id;
        private String data;
        //...ommited...
    }

supposing i have this CrudSync entity.

On the N clients side database, i would have a table with columns:

ID - Number - PK
Data - Varchar
etc...

on the 1 Server side, i would like to have a table with:

ID - Number - PK
ClientPK - Number  // the ID on Client database table
ClientId - Number  // the Client code (1,2,3,4.. etc..)
 // UQ (ClientPK,ClientID)
Data - Varchar
etc...

or even a composite PK

ClientPK - Number - PK // the ID on Client database table
ClientId - Number - PK // the Client code (1,2,3,4.. etc..)
Data - Varchar
etc...

but i am not sure how to achieve that using the same Entities on both sides, if its even possible..

another solution could maybe create separated JAR/EAR for Client and Server. doing that, what should i change in Entities/JPA annotations? what class should be separated to Client/Server JAR/EAR ?

Any other suggestion on how to make a (N Client <-> 1 Server) database?

Its mandatory to Clients work offline, so they need to have their own Database running, also its mandatory to have the same application on Server, because it will be possible to create entities on Server and those will be sent to Client (vice-versa).

I am using JBoss AS 7.1, JPA 2, EJB 3.1.

Thanks in advance. Anon.

4

1 回答 1

0

即兴发挥,不确定是否可以使用相同的 JPA 实体来做到这一点。逻辑可能会足够复杂,您可能希望它驻留在应用程序中而不是数据库中。

也就是说,您可以使用装饰器模式,以便服务器/客户端应用程序可以使用相同的核心 JPA 实体。然后拥有特定于服务器的 JPA 实体,这些实体装饰核心实体并持久化管理客户端和服务器应用程序之间的同步所需的数据。装饰器对象只包含对核心对象的引用。然后它需要任何数据来促进服务器和客户端之间的数据推送和拉取。

希望这可以帮助

于 2013-04-23T22:34:58.780 回答