我以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
方法客戶列表頁面。
當我按下按鈕我收到錯誤There was no DB provider available, unable to create connection
。它看起來像SchemaExport
正在創建DBProvider
爲空。
完整的錯誤文本:
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
它看起來像從本地會話工廠拉出的配置沒有完全填充,使用彈簧方法解決了這個問題。 public void MakeANewDatabase(){ LocalsessionFactory.CreateDatabaseSchema(); } – Portalus 2011-06-16 22:00:02