Below is my perisistence.xml, having the datasource.
<persistence-unit name="employee" transaction-type="RESOURCE_LOCAL">
<non-jta-data-source>jdbc/MyDS</non-jta-data-source>
</persistence-unit>
我正在尝试独立创建EntityManager,但无法执行示例查询,请帮助我。
public static void main(String[] args) {
Map<String, String> properties = new HashMap<String, String>();
// Ensure RESOURCE_LOCAL transactions is used.
properties.put("javax.persistence.transactionType",
PersistenceUnitTransactionType.RESOURCE_LOCAL.name());
// Configure the internal EclipseLink connection pool
properties.put("javax.persistence.jdbc.driver" , "oracle.jdbc.OracleDriver");
properties.put("javax.persistence.jdbc.url", "jdbc:oracle:thin:@localhost:1521:ORCL");
properties.put("javax.persistence.jdbc.user", "scott");
properties.put("javax.persistence.jdbc.password", "tiger");
// Ensure that no server-platform is configured
properties.put("eclipselink.target-server", TargetServer.None);
entityManagerFactory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME,properties);
entityManager = entityManagerFactory.createEntityManager();
Query query = entityManager.createQuery(" select d from XyzEntity d");
List<XyzEntity> xyzEntityList = query.getResultList();
System.out.println("size is"+xyzEntityList.size());
}
上面的代码仍在寻找数据源。
请帮我。