我从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方法的customer List页面添加了一个按钮。
当我点击按钮时,我收到了错误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发布于 2011-06-20 06:23:51
从本地会话工厂拉出的配置看起来没有完全填充,使用spring方法解决了这个问题。
public void MakeANewDatabase()
{
LocalsessionFactory.CreateDatabaseSchema();
}https://stackoverflow.com/questions/6374267
复制相似问题