Hi,
I came across a design architecture I hadn't seen before -- no surprise there, but maybe you could enlighten me.
1) Many JPA entity pojos are defined in the Spring context using XML. The pojos have no injected dependencies. They are not subclassed. They are not used within another bean definition. They look like this:
<bean id="my.entities.MyEntityPojo" class="my.entities.MyEntityPojo" singleton="false"/>
@Entity
@Table(name="my_table")
public class MyEntityPojo implements Serializable{
...
}
2) The pojos are accessed via the appContext.getBean method, wherever they are needed throughout the entire application. Like so:
MyEntityPojo pojo = (MyEntityPojo) appContext.getBean("my.entities.MyEntityPojo");
3) The idea is that creating an object with 'new' is bad. appContext.getBean is better, the pojos benefit from the Spring context. It is more efficient, the JVM is not burdened with garbage collection, and the objects are pooled and managed with Spring goodness.
4) I will repeat, there are no injected dependencies and the bean id is not used within another bean. There are no plans for doing so.
Ok. Does anyone have any thoughts on point #3? Is this genius, or madness? Have I gone down the rabbit hole or are there good reasons for doing this?
Thanks!



Reply With Quote
