Sub-classing your EntityManagerFactory can't be a good idea, unless you really really know what you are doing.
Code:
@Repository
public MyFooDaoImpl implements MyFooDao {
@PersistenceContext(unitName="persistenceUnit1")
private EntityManager em;
@Transactional
public Integer getSomething(Integer valueOne) {
return em.doSomething(valueOne);
}
}
A quick google givens me some links which explain things better than I can do here.
http://blog.springsource.com/2006/08...encing-spring/
Look at the example above, you need a bean org.springframework.orm.jpa.support.PersistenceAnn otationBeanPostProcessor in order to process annotation based @PersistanceContext. http://static.springsource.org/sprin...Processor.html
You can provide a Persistence Unit Name in your EntityManagerFactory creation. This would be the:
Code:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean" />
Which again can be explained at http://static.springsource.org/sprin...ctoryBean.html checkout the setPersistenceUnitName() in the Abstract base-class it uses.
I would not call your persistance unit name the same name as a well known other kind of object "dataSource" this seems like a bad choice to make. Call your persistence unit "persistenceUnit1". Note the persistance unit name, is a label for the ORM Factory ("entityManagerFactory" aka EMF) is called, in the context of a larger JEE and app-server there maybe multiple PUs in the one system. Check the documentation for ORM http://static.springsource.org/sprin...rence/orm.html (section 12.6) note in JPA you can specify the dataSource in the persistence.xml but can override it in Spring configuration, see section 12.6. In summary the persistanceUnitName is nothing to do with the underlying JDBC connection source, a persistanceUnitName is a JEE naming concept that is part of the JPA specifications. Think of it like a "bean name or bean id" given to the EMF but because it is part of JPA spec that spring concept works in a JEE that implements JPA but does not use Spring.
There is no reason at all for you to subclass any class in order to override a setter
with spring XML configuration just declare a bean and access the property to set it.
If you only have a single EntityManagerFactory built for your entire spring project, you do not have to concern yourself with using a persistance unit name. If you use the default bean naming conventions from the blog example (1st URL above) things should be found automatically. If you do indeed require more than 2 PUs then consider getting one working first, then duplicate, then work on the issue of injection qualification via persistance unit names.
Feel free to hunt the exact version of documentation for your version of spring. Consider trying a cut down example project just to get things working on a smaller scale.