尝试创建数据库架构 - 没有可用的数据库提供程序,无法创建连接

发布于 2024-11-16 01:11:04 字数 2461 浏览 1 评论 0原文

我从 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 方法。

当我点击按钮时,我收到错误没有可用的数据库提供程序,无法创建连接。看起来,当创建 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天邊彩虹 2024-11-23 01:11:04

看起来从本地会话工厂拉取的配置未完全填充,通过使用 spring 方法解决了该问题。

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

It looks like the config pulled from the local session factory is not fully populated, Solved the issue by using spring methods.

public void MakeANewDatabase()
{ 
  LocalsessionFactory.CreateDatabaseSchema(); 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文