NHibernate Many-To-Many Issues and Solution

I was having a few issues with NHibernate Many-To-Many relationships, I was trying to link sample types with physical locations via a many-to-many so you could not put a sample into a container that did not allow it’s type.

I initially set this up using a single many-to-many mapping on the Physical Location side with inverse set to true

<bag name="LimitedTypes" inverse="true" lazy="true" cascade="none" table="pLocLType">
      <key column="pLocTypeid" />
      <many-to-many class="spring.pxl.Domain.SampleType,spring.pxl.Dao" column="typeid" />
</bag>

While in initial testing this worked when I manually entered data into “pLocLType” table I could pull our of the pLocLType object all the links, and this worked, however when running integration tests, I found that if I added an element to the [LimitedTypes] IList the field in the database was not being populated when I saved it. Time to look at the relationship again.

After a bit of tinkering I came across my problem, I needed the mapping in both the  pLocLType mapping file and the SampleType mapping file, I also needed to have inverse=”true” on only one of the bags. Which makes sense considering what inverse means, it is nHibernate’s way of fobbing off responsibility to another class, but if you have them both set to true, then object 1 says object 2 should do it and object 2 says object 1 should do it and in the end nothing gets done.

<bag name="LimitedTypes" lazy="true" cascade="none" table="pLocLType">
      <key column="pLocTypeid" />
      <many-to-many class="spring.pxl.Domain.SampleType,spring.pxl.Dao" column="typeid" />
</bag>
<bag name="LimitedPlocs" inverse="true" lazy="true" cascade="none" table="pLocLType">
      <key column="typeid" />
      <many-to-many class="spring.pxl.Domain.SamplePLocType,spring.pxl.Dao" column="pLocTypeid" />
</bag>

This however worked and the integration tests could continue.

One of the most useful tutorial videos for more advanced JavaScript

I can’t stop telling people about this video 10 Things I Learned from the jQuery Source by Paul Irish at http://net.tutsplus.com. This is a great video which delves into how jQuery works, and how you could use the cleverness outside of a jquery application. One example, and only one because you should watch the video if you are interested in learning more, which opened my eyes was the most basic starting feature of jQuery the Self-Executing Anonymous function and using it with setTimeout() to replace the use of setInterval().

(function(){
// come code here
})();

This function will call itself and if you put a setTimeout() inside it to call itself again you can get a very similar effect to setInterval() with the key exception that if you were to setInterval(methodname,10) and it takes longer than 10ms to run the method this will keep calling it even though the last query had not finished yet, whereas by using setTimeout(self,10) you will still get the 10ms break between calls but it will only start counting when the previous call finishes.

Rust Paint Effect

I am currently working on building an Warhammer 40k Ork Army, and in the process I have enjoyed learning about the different painting effects to work my way up to the standard of the Games Workshop ’Eavy Metal  Team who are quite frankly awesome painters.

In the process of building the army I have gathered a few vehicles and wanted to create a more realistic rust effect, Orks don’t keep their things nice and shiny, so I was looking around for different effects to achieve this.

From the simpler Red, Brown, Silver effect by MiniWargaming which is great and quick, but not quite what  I wanted to achieve Warhammer Rust Effects Guide from MiniWarGaming.

From that I came across CedarRed12‘s video which was very similar but still not what I wanted to achieve Warhammer 40k How to Paint Rust

Then I came across a brilliant 3 part series by Girlpainting which was awesome and did the job fantastically. Can’t recommend this one enough.

How to weather a surface with the hairspray and salt method part 1

How to weather a surface with the hairspray and salt method part 2

How to weather a surface with the hairspray and salt method part 3

Also I incidentally came across a video by warmonger GD who uses Pigments which is similar to the process I use already Hammer40k How to Paint Weathering Pigments “Rust Effect”

Really loving iTunes backup

Recently I suffered the disaster of my iPhone dropping onto a concrete floor and the screen smashing, luckily I had insurance and luckily I backed up my iPhone using iTunes. So I sent it off to them on Tuesday and had a new iPhone in my hands by Thursday which was great, and it was definitely new as the IMEI and Serial numbers had changed.

I plugged it into my computer and hit restore from backup in iTunes and after a bit of waiting my phone is practically the same, minus the apps and music which I needed to add again, seriously, all my contacts, text messages, call logs, notes, and even logins for certain apps. most of which I had come to terms with losing, but no, it was all restored. Great!

Added Twitter functionality

I’ve just added the Twitter Widget Pro plugin so that people visiting this site can see I’m actually still alive. I have recently been hitting a sort of writers block, as I am having trouble coming up with things to post. Twitter I find is much easier just for day to day thoughts, so if you want to follow me my name is @cjchestnut.

The plugin after a few niggly problems has worked out quite well, still needs a little styling, but I’m almost happy with it. The setup was very simple once I discovered I needed to add it to the menu as well as activate it. The options are very useful and simple to use, and it gives you many options for styling to your hearts’ content.

Working with JavaScript again and wanting to prepend an element to the page

I am getting back into the swing of using JavaScript again and I am dynamically adding elements to the page quite easily using

var elem1 = document.createElement("div");
... some code to do something ...
document.getElementsByTagName("body")[0].appendChild(elem1);

Which simply adds the new element to the end of the page, or if I had appended it to an element in the page it would appear at the end of that element. However I needed it to be generated at the front of the dom element before any others.

I had done this before but thanks to the wonders of google I quickly found what I needed to know. Now yes it would be very easy to do this using jQuery but that involved adding another library to the page, this would have been silly seeing this was the only thing required. What I forgot about was the good old insertBefore()

var theparentElement = document.getElementById("container");
var elem1 = document.createElement("div");
... some code to do something ...
theparentElement.insertBefore(frame, theparentElement.firstChild);

For reference the most useful site on the subject I found in the 20 seconds of looking was http://developer.practicalecommerce.com/…

A New Beginning

I went down the Joomla route initially after the disastrous server failure which crippled this website and forced me to change hosting providers, I found it was like using a bargepole for a crutch, it was bloated and all I really wanted was a simple blog, which hopefully could be expanded at a later date to have the same features the old site used to have. Lets see if this CMS does any better.