Java EE 6 - The Persistent Domain Objects pattern - any successes?

人盡茶涼 提交于 2019-12-03 13:48:22

No replies so maybe I'm the only one doing it ;) For anyone else looking for pointers, I have found:

  • your object model needs major modification. You can't use Maps or Lists of interfaces as you would in a non-JPA app, because JPA can't "handle" interfaces, you need to persist (abstract) classes. Hibernate has an @Any and @ManyToAny annotation, but the overhead (performance, functionality and coding) is (IMHO) significant. If you can implement a hideous abstract class hierarchy then you should. YUK!

  • If you have a vaguely complex object model (more than six relationships between objects) you will end up with LOTS of JOIN commands in the SQL code that is generated by the JPA engine. I read somewhere that >6 JOINS puts a high load on the database (just a rule-of-thumb I'm sure). MySQL has a hard limit of 61 joins. Sounds crazily high, surely you'd never hit that?! If you've got an abstract object hierarchy and a few relationships between objects it soon adds up!

I haven't found a way to get around the first "problem". It feels wrong to ram-in lots of abstract base classes instead of interfaces, but it's unavoidable as far as I can see. Please tell me if not!

The second problem can be managed by using lazy-fetch on object relationships, or by using Adam's Gateway pattern and extended persistence sessions (rather than stateless session beans loading and saving the model on every call). I'm going with the latter so far - but haven't got to a point where I can load-test on the memory and database usage yet. We'll see!

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