English 中文(简体)
是否有可能建立遥控实体?
原标题:Is it possible to have remotely managed entities?

我不太熟悉联军,但我有这种设想: 出于科索沃统计局/DRY的原因,我想在服务器和客户(Java SE)上使用相同的班级(现为“密码”。 在我看来,这样做的一个可能办法是,在客户上设置一个(特别的)<代码>EntityManager,将实体的请求传递给服务器,最终让所有实体回到服务器上来,以开展“批量持续行动”,使各个班级能够(重新)验证其数据,实施一些交易业务(更新和装饰),并且完全由联合邮局执行。

问题是:这是可能的吗? 如何? 是否有解决办法? 用“某些”法解决这一问题,是简单而简单的。


<><>Edit>: 奥基先生,请允许我向大家澄清几个问题。 我的背景是,有一个内部增长的应用程序框架,利用所谓的通用持久性服务;即,在单一交易中开展“团结、团结和团结”行动(每张表格都有一项服务),但得到(在服务中)拦截这些行动和提供验证的班级的支持;以及(往往是)复杂的业务规则(对其他表格进行更新等)。 这与旧的微软产品一起实施。 现在出现了转变。 NET,其中最近出现了类似工作但更先进的框架,如Devforce和CSLA。 “Devforce”尤其向 Java提供我喜欢做的事(见,然后访问s/thi page

关于这个一般性议题的较老的地雷问题:

问题回答

我以前曾试图做过类似的事情,或许只是就我的调查结果谈一旁(当时我正在利用Hibernate + XFire为WS)。

我认为,你们的思想在理论上是行之有效的。 你们需要做的是,简单地将管理的实体编成册,并将其发送给客户。 客户(当然,客户终端,完全是正常的POJO,而不是管理的实体),将其送回服务器。 此时此刻,被服务器击落的物体只是一个过时的物体。 你可以回头来开会(JPA/Hibernate将为你们做这些乐观的一致检查),并坚持不懈。

However it only works fine for very simply POJO. One of the major problem is, in JPA (or mostly all ORM framework) you are having relationships between different entities. For example, an Order will have relationships to Product and Account, an Account will have relatinships to Client, Client will have list of Addresses.... etc. It is mostly fine if you are manipulating in server side because of lazy fetching, relationships are not actually fetched until you access it. However when you perform serialization, it become a difficult problem to solve: most serialization solution like JAXB will simply navigate all properties recursively. The result is, you expect to send only the Order object to client side, but finally you are sending a huge piece of data to Client. Simply telling the serializer not to serialize some properties is not going to work, coz when the object is sent back and reattach the detached obj to session, JPA/Hibernate have no way to know that if you are simply ignoring the relationship or you are actually removing the relationship. Of course there are still some tricks you can do but all these makes such approach painful to adopt and it is no longer elegant.

你的想法是明智的。

但不可能做你所建议的。 为什么没有? 为了回答这一点,我们必须首先理解“什么是管理的实体”。

A managed entity is nothing else than "cached" instance. An instance that resides inside the entity manager. If you send this instance throught the network to another machine, you are serializing it, thus copying it: creating another instance on the remote server that, of course, is not managed (because the entity manager doesn t even know about its existence).

In the other side there could exist something "smart enough" to simulate an entity manager and trasparently "manage" this copied entity, but this is out of the JPA specification, and you would have to implement it yourself (which doesn t seem to be easy). I don t think that there exists anything reliable out there for this.

你的解决办法是坚持下去,更新,等等明确来自客户(通过服务器暴露的方法)。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签