We use the NServiceBus generated NHibernatePersistence mappings for our Sagas. I'd like to take a look at these mappings to help diagnose a problem and potentially serve as a starting point for some tweaks that we may need to make to these mappings.
With something like FluentNHibernate I could use an ExportTo method in order to dump out the generated hbm files. Is there something similar that I could use to dump out the default mappings that nservicebus is using for our sagas? Or is there some other way to go about exporting the generated mappings?
You can use the ScriptGenerator class as shown in this test. Combined with something like ApprovalTests, ScriptGenerator can make sure that the schema changes are always explicitly approved.
Related
When I Add-Migration, I get the appropriate DbMigration class with the Up / Down methods, where I am able to make schema changes and (with the use of the Sql() method) can make data/content changes as well.
I'd like to be able to make content changes per migration using the database context. I understand that I could use the Seed method in a Configuration class, but my understanding is that I can only wire up one Configuration with my initializer.
I'd prefer to have a UpCompleted()/DownCompleted() methods that would provide access to the db context after the migration completed. This would enable writing incremental data/context change "scripts" in a manner that would be less prone to errors than using the Sql() method.
Am I missing something? Is this possible?
Thanks!
That doesn't really work because the context only has your most recent model - which can only be used to access the database once the most recent migration has run (which is effectively what Seed achieves).
For an example of how this idea breaks, if you moved a property from one class to another then seed logic from older migrations would no longer compile. But you couldn't change it to use the new property because the corresponding column wouldn't exist in the database yet.
If you want to write this kind of seed/data-manipulation logic, you need to put it at the end of the Up/Down methods and use the Sql method to perform it using raw SQL.
~Rowan
I'm not a big fan of XML files. Therefore I'm wondering if there is a way to use eclipselink without its persistence.xml configuration file. Why?
Because I want to manage different databases dynamically. It would be much easier to do it without the XML file.
I'm surprised that I couldn't find anything on the web for now.
Not really, but you could create an EclipseLink ServerSession directly and wrap it with an EntityManagerFactoryImpl, but I would not suggest it.
You would be better off creating a persistence.xml. You can still do dynamic databases, you just need to pass a properties file to createEntityManagerFactory(Map) that include your database info.
Though it is not an direct answer to your question, this will help for the second part of your question. For managin multiple database connections, you can define multiple server sessions in sessions.xml and access those where you want.
you may use follwoing lines for accessing particular session
ServerSession aSession = = (ServerSession) SessionManager.getManager().getSession("session_2");
I have an existing NServiceBus 2.6 application that I want to start moving to 3.0. I'm looking for the minimum change upgrade in the first instance. Is this as simple as replace the 2.6 DLLs with the 3.0 Nuget packages or are there other considerations?
For the most part the application migration is quite straight forward, but depending on your configuration and environment, you may need to make the following changes:
The new convention over configuration for endpoints may mean you will need to rename your endpoints to match your queue names (#andreasohlund has a good post about this).
persistence of saga, timeouts, subscriptions etc. now defaults to RavenDb, so if you use SQL Server to persist data, you need to make sure you have to correct profile and endpoint configuration. For SQL Server storage, make sure you add a reference to NServiceBus.NHibernate as it is no longer part of the core.
Error queues are now referenced differently using different configuration ie. use MessageForwardingInCaseOfFaultConfig instead of the regular MsmqTransportConfig error property. You should still be able to use it, but it will look for the MessageForwardingInCaseOfFaultConfig first.
Other than that, I don't think you need to do anything else to get you upgrade working. I modified some of my message definitions to take advantage of the new ICommand and IEvent interfaces as a way communicatinf intent more clearly.
Anyway, I'm sure there will be some cases that are specific to your environment that will require different changes but I hope this helps a bit.
I am building a composite (Prism) WPF application. I hava managed to build some core elemets: for example module discovery from folder.
I am also using NHibernate (Fluent) to persist data. I was able to separate modules so every has it's own model and mapping, and when Prism adds module it also adds mappings to my nh configuration.
What I would like to do is to insert some startup records when a module, that has never been started, is enabled.
For example:
When I first start my app, it detects that there is no db and creates one, only with one configuration table. This table contains info about which module is enabled. Then admin can configure app through UI which modules should be enabled. Next time the app starts it detects new tabs from newly enabled modules and creates their tables using NH UpdateSchema. What I would like to do is to also insert some startup records with this table create.
I think this should be done by NH events (NH documentation on events). Something like 'PostTableCreateEvent' would be nice but I can't find anything like this.
Did any of you do something like this?
Events are triggered in sessions but Schemaexport doest take sessionfactories or sessions, so you cant hook in there. For this what you want there is <database-object><create>INSERT ...</create><drop></drop></database-object> in xml mappings or plain sql since FNH doesnt support <database-object> afaik.
Option 1: add fluent and hbm.xml mappings on creation of NH-Configuration and embed Mappings with <database-object>
Option 2: allow Modules to take additional steps (sql) after Creation of tables ( for one of my projects i wrapped Schemaexport in my own class/Method which also creates the database itself which isnt handled by schemaexport and inserts custom data like schemaversion and configs)
I'd like to have a single configuration file and then when I'm creating a session change the hibernate-configuration->session-factory->connection.connection_string property to what I want it to be programmatically? Is it possible?
UPDATE:
I believe I may be able to do this like this
Configuration cfg = new Configuration();
cfg.Configure(sessionFactoryConfigPath);
cfg.Properties["connection.connection_string"] = ...
What I would wonder than, if that is ok, Is this a bad way to handle connecting to a different database for each session? if so why etc. I'd also like to know if/how you can open an nhibernate session with a .net connection object?
Use the ISessionFactory.OpenSession() overload that takes a IDbConnection.
That's how Castle's DifferentDatabaseScope does it.
I think it is better to use different configuration files per each data base just becouse you will be able to switch dialects very esasy.
You may also see this answer as it allows full configuration of session factories through one file. Configure NHibernate hibernate.cfg.xml file to have more connection strings