|
From: Thomas R. <tho...@tr...> - 2006-03-11 17:10:32
|
I've been examining the JPA support in 2.0 and i have a few issues around the JpaDaoSupport class. There are two ways of configuring this class - either you provide an EntityManager or an EntityManagerFactory. Which one you provide dictates what JpaDaoSupport methods you can effectively use later on in your code. This, I think, couples your code to configuration choices. If you provide an EntityManagerFactory then the getEntityManager method returns null and you are forced to use getEntityManagerFactory method. If you provide an EntityManager, then it's the other way around, you must use the getEntityManager method since getEntityManagerFactory returns null. This EntityManagerFactory/EntityManager issue provides a non- intuitive split in the API usage and will confuse the heck out of everyone. We need to come up with some strategy to make it easier to directly use an EntityManager instance for both configuring this class and for gaining access to an instance of EntityManager that will participate in Spring managed transactions regardless of how the JpaDaoSupport was configured. I would prefer to have a solution where we can do the right thing behind thes scenes instead of simply returning a null. We should either return a "managed" object of the type requested or throw and InvalidApiUsage type exception. Thomas |