尝试创建数据库架构 - 没有可用的数据库提供程序,无法创建连接
我从 Northwind spring.net/NHibernate 示例开始。我正在尝试使用现有示例来生成架构。我将 CustomerEditController web.xml 条目更改为
<object name="CustomerEditController" type="NHibernateCustomerEditController" scope="session">
<constructor-arg name="sessionFactory" ref="NHibernateSessionFactory"/>
<constructor-arg name="local" ref="&NHibernateSessionFactory"/>
</object>`
将 NHibernateCustomerEditController
更改为以下内容:
public class NHibernateCustomerEditController : ICustomerEditController
{
private readonly ISessionFactory sessionFactory;
private readonly LocalSessionFactoryObject LocalsessionFactory;
private Customer currentCustomer;
public NHibernateCustomerEditController(ISessionFactory sessionFactory, LocalSessionFactoryObject local)
{
this.sessionFactory = sessionFactory;
this.LocalsessionFactory = local;
}
private ISession Session
{
get { return sessionFactory.GetCurrentSession(); }
}
public void EditCustomer(Customer customer)
{
currentCustomer = customer;
}
public void Clear()
{
currentCustomer = null;
}
public Customer CurrentCustomer
{
get
{
Customer customer = currentCustomer;
//since the Customer entity may have been retrieved from a prior request, we need to reattach it to the current session
// in order to support lazy-loading, etc. on the Customer
Session.Lock(customer, LockMode.None);
return customer;
}
}
public void MakeANewDatabase() {
SchemaExport schema = new SchemaExport(LocalsessionFactory.Configuration);
schema.Create(true, true);
}
}
我向客户列表页面添加了一个按钮,该按钮通向 MakeANewDatabase
方法。
当我点击按钮时,我收到错误没有可用的数据库提供程序,无法创建连接
。看起来,当创建 SchemaExport
时,DBProvider
为 null。
完整错误文本:
An exception of type 'System.Exception' occurred in Spring.Data.NHibernate30.DLL but was not handled in user code
Additional information: There was no DB provider available, unable to create connection
An exception of type 'NHibernate.HibernateException' occurred in NHibernate.DLL but was not handled in user code
Additional information: There was no DB provider available, unable to create connection
I started with the Northwind spring.net/NHibernate example. I am trying to get the existing example to generate a schema. I altered the CustomerEditController web.xml entry to
<object name="CustomerEditController" type="NHibernateCustomerEditController" scope="session">
<constructor-arg name="sessionFactory" ref="NHibernateSessionFactory"/>
<constructor-arg name="local" ref="&NHibernateSessionFactory"/>
</object>`
Changed the NHibernateCustomerEditController
to the following:
public class NHibernateCustomerEditController : ICustomerEditController
{
private readonly ISessionFactory sessionFactory;
private readonly LocalSessionFactoryObject LocalsessionFactory;
private Customer currentCustomer;
public NHibernateCustomerEditController(ISessionFactory sessionFactory, LocalSessionFactoryObject local)
{
this.sessionFactory = sessionFactory;
this.LocalsessionFactory = local;
}
private ISession Session
{
get { return sessionFactory.GetCurrentSession(); }
}
public void EditCustomer(Customer customer)
{
currentCustomer = customer;
}
public void Clear()
{
currentCustomer = null;
}
public Customer CurrentCustomer
{
get
{
Customer customer = currentCustomer;
//since the Customer entity may have been retrieved from a prior request, we need to reattach it to the current session
// in order to support lazy-loading, etc. on the Customer
Session.Lock(customer, LockMode.None);
return customer;
}
}
public void MakeANewDatabase() {
SchemaExport schema = new SchemaExport(LocalsessionFactory.Configuration);
schema.Create(true, true);
}
}
I added a button to the customer List page that leads to the MakeANewDatabase
method.
When I hit the button i receive the error There was no DB provider available, unable to create connection
. It looks like when the SchemaExport
is being created the DBProvider
is null.
Full error text:
An exception of type 'System.Exception' occurred in Spring.Data.NHibernate30.DLL but was not handled in user code
Additional information: There was no DB provider available, unable to create connection
An exception of type 'NHibernate.HibernateException' occurred in NHibernate.DLL but was not handled in user code
Additional information: There was no DB provider available, unable to create connection
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来从本地会话工厂拉取的配置未完全填充,通过使用 spring 方法解决了该问题。
It looks like the config pulled from the local session factory is not fully populated, Solved the issue by using spring methods.