java以编程方式创建实体管理器,无需持久性文件
我正在尝试以编程方式创建实体工厂管理器,而不使用持久性文件
EntityManagerFactory emf;
Map<String, String> properties = new HashMap<String, String>();
properties.put("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
properties.put("hibernate.connection.url", "jdbc:mysql://173.194.25***************");
properties.put("hibernate.connection.username", "etech****");
properties.put("hibernate.connection.password", "A*****");
properties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
properties.put("hibernate.show-sql", "true");
properties.put("provider", "org.hibernate.ejb.HibernatePersistence");
emf = Persistence.createEntityManagerFactory(idClient, properties);
在线
emf = Persistence.createEntityManagerFactory(idClient, properties);
我得到了一个错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com****RepositoryFieldsFieldWorkerRepositoryImpl': Invocation of init method failed; nested exception is javax.persistence.PersistenceException: No Persistence provider for EntityManager named idClient
如何解决这个问题
任何帮助都将不胜感激
# 1 楼答案
根据JPA规范,在部署时必须使用
persistence.xml
文件来创建持久化单元见Create JPA EntityManager without persistence.xml configuration file