Mapping POJO to Entities

…衆ロ難τιáo~ 提交于 2019-12-22 07:04:17

问题


In our project we have a constraint of not having the luxury to alter the table structure already in place. The tables are highly denormalized in nature.

We have come up with good POJOs for the application. We have the Entity beans generated out of the exiting tables. Now we have to map the POJOs to the entities so that we can persist.

Ultimately, we combine a good POJO with a bad table. Any thoughts on options/alternatives/suggestions to this approach?


回答1:


Hibernate/JPA(2) has a rich set of functionality to manipulate the mapping (so that your objects can differ from the tables), so that many (NOT ALL) old tables can be mapped to normal object. -- May you should have a look at this first, any use your pojo/table-"solution" only if this mapping is not powerful enough.


If you have a read only application, you can think of using views to make your table/views more like you objects. This may reduse the amount of strange mapping.


I don't know your mapping, size of the application or use case, but have you considered not to use Hibernate? I ask this, because I can imagine (how I said: I don't know you application), that in a architecture like this, no Hibernate feature is used and so Hibernate will add only a not needed complexity.




回答2:


If you are using Hibernate you should be able to map your POJOs to the table structure using only XML files, without creating new Java beans. This would allow you to easily change the mapping if all of a sudden you can change the tables structures and make the economy of intermediary beans. That's the best you can do.



来源:https://stackoverflow.com/questions/5617612/mapping-pojo-to-entities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!