Roa*_*tad 11 playframework squeryl
我试图在Play 2.0框架中使用Squeryl ORB,但DB.getConnection()
在初始化期间调用时我得到:
错误路径:路径参数:无效路径' - 无法找到defaultdb的数据源':路径表达式中不允许使用令牌:' - '(如果您真的需要,可以双引号此令牌)
数据库配置如下所示(conf/application.conf):
db.default.url="jdbc:postgresql://localhost/mydb?user=postgres&password=postgres"
db.default.driver=org.postgresql.Driver
db.default.jndiName=defaultdb
Run Code Online (Sandbox Code Playgroud)
并初始化:
object Global extends GlobalSettings {
override def onStart(app: Application) {
SessionFactory.externalTransactionManagementAdapter = Some(() =>
Some(new Session(
DB.getConnection("defaultdb", true),
new PostgreSqlAdapter)))
...
Run Code Online (Sandbox Code Playgroud)
这是正确的方法吗?使用db.default.jndiName
配置值作为参数值是否正确DB.getConnection()
?
或者应该这样做?:
SessionFactory.concreteFactory = Some(() =>
Session.create(
java.sql.DriverManager.getConnection("jdbc:postgresql://..."),
new PostgreSqlAdapter))
Run Code Online (Sandbox Code Playgroud)
这是有效的,但后来我无法在模板中使用squeryl查询对象进行迭代,我希望可以使用它externalTransactionManagementAdapter
.
我更正了以下内容:DB.getConnection("default", true)
并删除了db.default.jndiName
配置.有了这个,我能够获得并使用一个连接,但第二次getConnection()
被调用,它会抛出SQLException: Timed out waiting for a free available connection.
我没有设法使用externalTransactionManagementAdapter
,但concreteFactory
效果很好 - 如下所述.
接下来对我有用:
import play.db.DB
import play.api.Application
import play.api.GlobalSettings
import org.squeryl._
import org.squeryl.adapters._
Run Code Online (Sandbox Code Playgroud)
....
object Global extends GlobalSettings
{
override def onStart(app:Application):Unit =
{
SessionFactory.concreteFactory = Some(
() => Session.create(DB.getDataSource().getConnection(),
dbAdapter)
);
}
override def onStop(app:Application):Unit =
{
}
val dbAdapter = new PostgreSqlAdapter();
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2700 次 |
最近记录: |