2011-06-16 83 views
3

我以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="&amp;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 
+0

它看起来像从本地会话工厂拉出的配置没有完全填充,使用弹簧方法解决了这个问题。 public void MakeANewDatabase(){ LocalsessionFactory.CreateDatabaseSchema(); } – Portalus 2011-06-16 22:00:02

回答

3

它看起来像配置从本地会话工厂拉不完全填充,用弹簧的方法解决了这个问题。

public void MakeANewDatabase() 
{ 
    LocalsessionFactory.CreateDatabaseSchema(); 
} 
+0

为我节省了很多时间:) – hgulyan 2013-02-04 07:23:24