问题描述
我有一个工作应用程序,我使用Java EE 6和EclipseLink进行持久化和PostgreSQL数据库。
I have a working application where I use Java EE 6 with EclipseLink for persistence and a PostgreSQL database.
对于用户注册我想设置密码PostgreSQL:
For the User-Registration I want to set the password in PostgreSQL to:
... password = crypt('inputPassword',gen_salt('bf')) ...
由于我不能使用DigestUtils,我必须手动将用户插入数据库。
为了保持我的应用程序可配置,我不想使用
InitialContextInstance.lookup(dataSource)
查询DataSource,而是提取它(或连接) )以某种方式从EntityManager
喜欢:
As I cant use DigestUtils for this, I have to insert the user manually into the DB.To keep my application configurable I do not want to query the DataSource with anInitialContextInstance.lookup(dataSource)
but to extract it (or the Connection) somehow from the EntityManagerlike:
DataSource ds = entityManagerInstance.someFunctionThatReturnsADataSourceOrConnection();
或者可以使用createNativeQuery或类似的东西在
中使用预先准备好的语句防止注射?
Or would it be possible to use createNativeQuery or something similar in conjuntionwith a prepared statement to protect against injections?
推荐答案
有时它只需要在谷歌再次运行:
sometimes it just takes another run in google:
entityManager.getTransaction().begin();
java.sql.Connection connection = entityManager.unwrap(java.sql.Connection.class);
...
entityManager.getTransaction().commit();
如
这篇关于如何从Java EE 6中的JPA2 EntityManager获取DataSource或Connection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!