logo
Welcome to our new AbleCommerce forums. As a guest, you may view the information here. To post to this forum, you must have a registered account with us, either as a new user evaluating AbleCommerce or an existing user of the application. For all questions related to the older version of Gold and earlier, please go to AbleCommerce Gold forum. Please use your AbleCommerce username and password to Login. New Registrations are disabled.

Notification

Icon
Error

Options
Go to last post Go to first unread
judy at Web2Market  
#1 Posted : Thursday, May 20, 2021 6:40:00 AM(UTC)
judy at Web2Market

Rank: Advanced Member

Groups: Developers
Joined: 11/7/2018(UTC)
Posts: 286

Thanks: 21 times
Was thanked: 5 time(s) in 5 post(s)
Here I am again with a problem I had before. I am working on a new local site and have several custom tables I need to access. I have created .hbm.xml files, set them as embedded resource and have the appropriate object class, IRepository and Repository for them. I have them in the AbleCommerce namespace, they are in the Code folder, and I have added that mapping entry to the nhibernate.config file and added an entry into the windsor.config file for each. I compiled the solution and recycled the app pool and they don't pick up the database table. I even copied over a table and set of files that worked in another 9.0.4 site and they don't work.https://www.ablecommerce.com/for...rsister-for-custom-table
I even copied over the files and code you provided for the customPriceQuotes and it doesn't work.
I have a previous 9.0.4 local site where I am getting an unable to locate a persister error for a data object that had been working and that works on the live site and all of a sudden it has quit working on my local.
Any suggestions on how to troubleshoot this?

We had used the same tables on Gold sites but had switched to using Fluent nHibernate there. Do you know if it's possible to use Fluent in AC9? I did find an article on Fluent and MVC Fluent and MVC
They have the following file to attach to the database. Do you know how I could connect it to the AC database? I don't want to hard code the connection string.

using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate;
using NHibernate.Tool.hbm2ddl;

namespace FluentNhibernateMVC.Models
{
public class NHibernateHelper
{
public static ISession OpenSession()
{
ISessionFactory sessionFactory = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008
.ConnectionString(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\data\Blog\Samples\FluentNhibernateMVC\FluentNhibernateMVC\FluentNhibernateMVC\App_Data\FNhibernateDemo.mdf;Integrated Security=True")
.ShowSql()
)
.Mappings(m =>
m.FluentMappings
.AddFromAssemblyOf<Employee>())
.ExposeConfiguration(cfg => new SchemaExport(cfg)
.Create(false, false))
.BuildSessionFactory();
return sessionFactory.OpenSession();
}
}
}

Thanks

Wanna join the discussion?! Login to your AbleCommerce Forums forum account. New Registrations are disabled.

nadeem  
#2 Posted : Thursday, May 20, 2021 10:08:20 AM(UTC)
nadeem

Rank: Advanced Member

Groups: Administrators, Developers, Registered, HelpDesk, Authorized User, Admin, System
Joined: 10/11/2018(UTC)
Posts: 109

Thanks: 17 times
Was thanked: 18 time(s) in 18 post(s)
Hi Judy,

Yes, it is possible to use Fluent NHibernate with MVC.

You don't need to hard-code the connections string. You can just provide the connection string name like this:

Code:
ISessionFactory sessionFactory = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008
.ConnectionString(x => x.FromConnectionStringWithKey("AbleCommerce"))
.ShowSql())
.Mappings(m => m.FluentMappings
.AddFromAssemblyOf<Employee>())
.ExposeConfiguration(cfg => new SchemaExport(cfg)
.Create(false, false))
.BuildSessionFactory();


Hope this helps!

Thanks!!
judy at Web2Market  
#3 Posted : Monday, May 24, 2021 6:25:55 AM(UTC)
judy at Web2Market

Rank: Advanced Member

Groups: Developers
Joined: 11/7/2018(UTC)
Posts: 286

Thanks: 21 times
Was thanked: 5 time(s) in 5 post(s)
Thanks. After I posted this, I went digging for the method that a developer here had used to configure Fluent for Gold. He had overridden the SessionFactory class and added
//Custom W2M code for FluentNHibernate
PersistenceModel persistenceModel = new PersistenceModel();

persistenceModel.AddMappingsFromAssembly(System.Reflection.Assembly.Load("__Code"));
persistenceModel.Configure(Configuration);

before
// Now that we have our Configuration object, create a new SessionFactory
_sessionFactory = Configuration.BuildSessionFactory();


I don't know how he figured out to put in _Code for the App_Code folder. I tried that a little bit, but got an error because of _Code but might keep working on that if I can't get the other way to work.
I also noticed in your DatabaseConfiguration class that you have the following. This site has source code so I might be able to adapt that. Does this pick up .hbm.xml files from the plugin, meaning the plugin wouldn't need to include a dll, but could include a separate mapping file?Thanks

private void ImportMappingsFromPlugins(Configuration configuration)
{
try
{
var manager = Plugins.PluginManager.Instance;
if (manager != null && manager.Plugins.Count > 0)
{
var plugins = manager.GetInstalledPlugins();
if (plugins != null)
{
foreach (var plugin in plugins)
{
try
{
if (plugin.ReferencedAssembly != null)
{
var resources = plugin.ReferencedAssembly.GetManifestResourceNames();
if (resources != null && resources.Length > 0 && resources.Any(r => r.EndsWith(".hbm.xml")))
{
configuration.AddAssembly(plugin.ReferencedAssembly);
}
}
}
catch (Exception e)
{
Logger.Info(e.Message, e);
}
}
}
}
}
catch (Exception e)
{
Logger.Info(e.Message, e);
}
}
nadeem  
#4 Posted : Monday, May 24, 2021 7:20:21 AM(UTC)
nadeem

Rank: Advanced Member

Groups: Administrators, Developers, Registered, HelpDesk, Authorized User, Admin, System
Joined: 10/11/2018(UTC)
Posts: 109

Thanks: 17 times
Was thanked: 18 time(s) in 18 post(s)
In Gold, Code folder was compiled into an assembly named '__Code' at runtime. That's why he was loading the assembly using name.

Code:
persistenceModel.AddMappingsFromAssembly(System.Reflection.Assembly.Load("__Code"));


The counterpart of the above in AC9 is

Code:
persistenceModel.AddMappingsFromAssembly(System.Reflection.Assembly.Load("AbleCommerce")); // where AbleCommerce is the assembly name in this case i.e. AbleCommerce.dll


Quote:
Does this pick up .hbm.xml files from the plugin, meaning the plugin wouldn't need to include a dll, but could include a separate mapping file?


The mapping files from the plugin will be automatically picked up but you will need to add the reference of the CommerceBuilder.dll.
thanks 1 user thanked nadeem for this useful post.
judy at Web2Market on 5/24/2021(UTC)
judy at Web2Market  
#5 Posted : Monday, May 24, 2021 8:30:38 AM(UTC)
judy at Web2Market

Rank: Advanced Member

Groups: Developers
Joined: 11/7/2018(UTC)
Posts: 286

Thanks: 21 times
Was thanked: 5 time(s) in 5 post(s)
Thanks for the additional info.
I did finally figure out why mappings weren't working in this new solution- I had typos in the field names of a couple of the hbm.xml files and that caused none of them to work. I still haven't figured out why I'm having issues with the other site where it used to work.
judy at Web2Market  
#6 Posted : Wednesday, June 2, 2021 11:40:51 AM(UTC)
judy at Web2Market

Rank: Advanced Member

Groups: Developers
Joined: 11/7/2018(UTC)
Posts: 286

Thanks: 21 times
Was thanked: 5 time(s) in 5 post(s)
Is there any way to step through code to debug why new objects are throwing the error unable to locate a persister? I have added code for 17 database tables and 12 of the classes work and the other 5 throw the error unable to load a persister. The hbm.xml files are embedded resources, there are entries in the windsor.config file for them with the correct name for the classes because that doesn't throw an error. To make sure I don't have typos, I have commented out all the fields except for the id in the hbm.xml and entity class files. (I had done that on classes before when I had typos- commented out all but the id and added the fields back in one a a time to see which threw the error.)
When I debug, I just get to the error and the innerexception is the unable to locate persister and I can't step into anything further than that.
Thanks
judy at Web2Market  
#7 Posted : Thursday, June 3, 2021 6:11:21 AM(UTC)
judy at Web2Market

Rank: Advanced Member

Groups: Developers
Joined: 11/7/2018(UTC)
Posts: 286

Thanks: 21 times
Was thanked: 5 time(s) in 5 post(s)
Just another note, I even tried generated mapping files using NHibernteMappingGenerator and got the same error.
https://archive.codeplex.com/?p=nmg
nadeem  
#8 Posted : Tuesday, June 8, 2021 5:45:30 AM(UTC)
nadeem

Rank: Advanced Member

Groups: Administrators, Developers, Registered, HelpDesk, Authorized User, Admin, System
Joined: 10/11/2018(UTC)
Posts: 109

Thanks: 17 times
Was thanked: 18 time(s) in 18 post(s)
I am sorry but it is hard to say anything without looking at the code. This is strange that some of the classes work and some didn't.
judy at Web2Market  
#9 Posted : Tuesday, June 8, 2021 6:01:56 AM(UTC)
judy at Web2Market

Rank: Advanced Member

Groups: Developers
Joined: 11/7/2018(UTC)
Posts: 286

Thanks: 21 times
Was thanked: 5 time(s) in 5 post(s)
I finally found the solution yesterday. I had a typo in one of the classes and it knocked out the ones that came after it. I finally had to exclude the problem classes from the solution and then add them back in to the solution and Windsor one at a time to narrow it down. I had been testing them one at a time as I created them, but when I hit one that didn't work, I didn't exclude the files from the solution, just commented out the entry in Windsor and the line of code that called it.
Thanks for your help.
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.