AbleCommerce Forums
»
AbleCommerce
»
General Questions
»
Having trouble picking up new table with .hbm.xml, etc
Rank: Advanced Member
Groups: Developers
Joined: 11/7/2018(UTC) Posts: 303
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 MVCThey 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
|
|
|
|
Rank: Advanced Member
Groups: Administrators, Developers, Registered, HelpDesk, Authorized User, Admin, System Joined: 10/11/2018(UTC) Posts: 110
Thanks: 19 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!!
|
|
|
|
Rank: Advanced Member
Groups: Developers
Joined: 11/7/2018(UTC) Posts: 303
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); } }
|
|
|
|
Rank: Advanced Member
Groups: Administrators, Developers, Registered, HelpDesk, Authorized User, Admin, System Joined: 10/11/2018(UTC) Posts: 110
Thanks: 19 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.
|
1 user thanked nadeem for this useful post.
|
|
|
Rank: Advanced Member
Groups: Developers
Joined: 11/7/2018(UTC) Posts: 303
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.
|
|
|
|
Rank: Advanced Member
Groups: Developers
Joined: 11/7/2018(UTC) Posts: 303
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
|
|
|
|
Rank: Advanced Member
Groups: Developers
Joined: 11/7/2018(UTC) Posts: 303
Thanks: 21 times Was thanked: 5 time(s) in 5 post(s)
|
|
|
|
|
Rank: Advanced Member
Groups: Administrators, Developers, Registered, HelpDesk, Authorized User, Admin, System Joined: 10/11/2018(UTC) Posts: 110
Thanks: 19 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.
|
|
|
|
Rank: Advanced Member
Groups: Developers
Joined: 11/7/2018(UTC) Posts: 303
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.
|
|
|
|
AbleCommerce Forums
»
AbleCommerce
»
General Questions
»
Having trouble picking up new table with .hbm.xml, etc
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.
Important Information:
The AbleCommerce Forums uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close