Thursday 3 December 2015

Spring, getSingleResult and RollbackException

Slipped up on the rollback exception banana skin again...

Let's have a recap, you get something like this in your logs:

Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly

What's happened?  Well somewhere in your transaction something got the hump and set the transaction rollback flag.  When the transaction tries to commit it sees this, rolls back and dumps that unhelpful message in your logs.  If you want to get forensic get your debugger out and follow these instructions to track down the culprit.

Wednesday 23 September 2015

Resizing a VM and Windows Licencing

vs

I have a number of VMs on SSD.  The Windows 7 VMs in particular have bloated over time and I had gotten into the bad habit of expanding their disk size to accommodate all the junk the Windows OS seems to accumulate and hoard.

Finally running out of disk space, I decided to clean them up.  Getting rid of the Windows junk is another story, there's lots of help around and make sure you check out this tool PatchCleaner.

After freeing up tens of gigabytes I wanted to reduce the size of the VM disk.  I use VMWare Workstation and unfortunately this task is far from simple.  Turns out you need to download the VMWare vCenter Converter tool and it copies your old VM across to a new VM with the reduced disk size.

And that's where the trouble starts, fire up Windows and it'll start demanding that you active Windows.

This is frustrating as the old VM had a legit, activated copy of Windows.  The type of licence seems to lock it to the old VM.  However, I'm not trying to game Microsoft here, the old VM was deleted and I have no other way of shrinking the VM disk than using the above technique.  All I'm really doing is the virtual equivalent of replacing a disk drive in a physical machine - that doesn't trigger a licence violation.

Windows licencing seems to use a formula to lock licences to machines.  Generally you can swap/add drives and memory, but you can't, say, switch motherboards.  So what was causing the issue in the VM?  After a little experimentation I found the "scsi0.sasWWID" setting in the VMX file to be important.  The new VM had a different value, when I changed it to the value from the old VMX file Windows booted up without demanding activation.

BTW, I don't know the full ramifications of changing the VM SCSI SAS Id so be extremely careful if you do tinker with it.

Tuesday 30 June 2015

Windows 7 Audio: The device is being used by another application

Had this problem recently, and it seems many many others have had it too.

My USB headset stopped working out of the blue.  I switched to another USB port and it worked for a few weeks until that too stopped working.  I don't know what triggered the failures, but probably an application not properly cleaning up after itself.

Opening "Playback devices" by right clicking on the sound icon in the bottom right corner of the Windows screen and then testing the device gave the "The device is being used by another application" error.  Thanks Windows, but which application exactly?

Some forum posts suggested using sndvol to determine, however this showed no other applications using the device.  Other posts suggested restarting the Windows Audio service, clicking or unclicking the exclusive access options from the device and disabling and enabling the device.  Nothing made the slightest bit of difference.  Eventually the headset stopped working in my final remaining USB port, so a solution had to be found...

The fix:  eventually (= best part of a day wasted) I stumbled upon this procedure:  Open the Device Manager.  Under Sound, video and game controllers find your device.  Double click on it, Driver tab, Uninstall.  Unplug the USB headset, and then plug it back in.  The drivers reinstalled automatically and the sound worked once again.  I had to do this separately for each port, and as I'm running VMWare I had to do it again for all the ports in the guest VMs.

My setup: Dell Precision laptop, Windows 7 Pro, Sennheiser PC26 USB headset, VM Workstation.

Tuesday 5 May 2015

lodash _.find() seemingly not working

lodash is an excellent JavaScript library that you should probably be making use of.  Before we go any further, I should make it clear that the find() method works just fine.

We're using lodash on a legacy project and I've made the same mistake with the find() method a couple of times now, so thought I'd document this amateurish mistake.

I find JavaScript's loose typing can lead to lazy practice.  You get used to automatic type conversion and forget to think about data types and data type conversion. Take this example:

HTML
<input type="text" id="myInput" />
<button onclick="printName()">Print Name</button>


JavaScript
var listOfPeople = [{name: 'dave', id: 1}, {name: 'john', id: 2}, {name: 'lisa', id:3}];
function printName() {
    var personId = document.getElementById("myInput").value;
    var person = _.find(listOfPeople, {'id': personId});
    alert (person.name);   
}


Simple stuff: we're reading the personId and then using _.find() to retrieve the person object from our internal data structure.  But it doesn't work, nothing is alerted!

Initially you might wrongly conclude _.find() is not working.  However, the issue is document.getElementById("myInput").value returns a string primitive.  The data structure stores the ids as number primitives.  The _.find() method does a strict comparision (===) and therefore it doesn't matter what the values are, a string primitive will never === a number primitive.  The solution is easy, change this line to:

var personId = parseInt(document.getElementById("myInput").value);

We're now comparing numbers with numbers and it works as expected.

JSFiddle: https://jsfiddle.net/ctwuh6e1/3/