问题描述
我有一个Java企业应用程序提供网络服务,有域层和Hibernate持久层。在这种特殊情况下,没有我送过线的对象,域对象和持久对象之间的巨大差异(目前)。
I have a Java enterprise application that provides a web service, has a domain layer, and a hibernate persistence layer. In this particular case, there is not a huge difference (at the moment) between the objects I send over the wire, the domain objects, and the persistence objects.
目前,应用程序使用DTO关于持久性侧和JAXB注解注释的是域类。但是,我越读,仔细想想,越这似乎倒退! (更何况还有很多code,以支持盲目来回之间的DTO的和域对象。)这似乎是大多数建筑师建议域模型思想促进JPA注解并创建DTO对在发送对象丝。
Currently the application uses DTO's on the persistence side and annotates the Domain classes with JAXB annotations. However, the more I read and think about it, the more this seems backwards! (Not to mention there is a lot of code to support the mindless back and forth between the DTO's and the Domain objects.) It seems like most architects suggest puting JPA annotations on the domain model and create DTO's for sending objects over the wire.
在我的情况下,可能我把两个JAXB和JPA(休眠)标注在我的领域类?
In my case, could I put both the JAXB and JPA (Hibernate) annotations on my domain classes?
让我的网络服务的门面,我的域名,我的执着都紧紧捆绑在一起的想法似乎很容易维护,但不关心我,这可能需要时间来改变。然而这是聪明创建Web服务端一组DTO类,并跳过DTO对持久性的一面?
The thought of keeping my web service facade, my domain, and my persistence all tightly bundled together seems easy to maintain, but does concern me as these may need to change in time. But would it be smarter to create a set of DTO classes for the web services side and skip the DTO's for the persistence side?
推荐答案
有不与两个JPA和JAXB注释标注相同类别中没有功能上的原因,我已经做到了我自己有时。它变得有点难以阅读,不过,有时你需要不同的一流的设计权衡与JAXB和JPA。根据我的经验,这些折衷通常意味着你最终有两个级车型。
There's no functional reason for not annotating the same class with both JPA and JAXB annotations, I've done it myself on occasion. It does become a bit hard to read, though, and sometimes you want different class design trade-offs with JAXB and JPA. In my experience, these trade-offs usually mean you end up with two class models.
这篇关于不要域类通常会得到JPA或JAXB批注或两者兼而有之?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!