新的EJB3,請幫助/解釋。無法創建EntityManager
裏面一個會話bean我宣佈一個EntityManager如下
@PersistenceContext(unitName="ScheduleUnit")
private EntityManager em;
和工作原理。但是,當我做到這一點
private EntityManager em;
private EntityManagerFactory emf;
public void myFunction() {
emf = Persistence.createEntityManagerFactory("ScheduleUnit");
em = emf.createEntityManager();
}
我得到以下錯誤:
A JDBC Driver or DataSource class name must be specified in the ConnectionDriverName property
請參閱本文,如果您編寫j2se應用程序:http://java.sun.com/developer/technicalArticles/J2SE/Desktop/persistenceapi/ – Dmitry 2010-04-15 12:53:36
感謝德米特里, 我使用Genonimo而不是Glassfish的J2EE服務器。我已經正確設置了數據源。 org.apache.openjpa.persistence.PersistenceProviderImpl myDatasource jta-data- source> com.skomarcorp.Schedule persistence-unit>。你能解釋使用@PersistenceContext和EntityManagerFactory之間的區別,以及爲什麼一個比另一個更好? –
duvo
2010-04-16 18:21:27
這是我的persistence.xml:
使用註釋使代碼更簡單:)在這種情況下,容器(geronimo)會自動解析到實體管理器的鏈接,並且EntityManager實例的生命週期由容器管理。請參閱http://java.sun.com/javaee/5/docs/tutorial/doc/bnbqw.html – Dmitry 2010-04-20 18:27:08