Monday, October 1, 2012

The database could not be exclusively locked to perform the operation. (Microsoft SQL Server, Error: 5030)

When you try to rename a database, you get the following error message:

Problem:
The database could not be exclusively locked to perform the operation. (Microsoft SQL Server, Error: 5030)

This can be resolved by the following:

sp_who

Check which Process id use your database (dbname) and kill the process:

kill 15

Where spid = 15 is the process that lock the database you are trying to have a lock on.

Monday, September 17, 2012

NHibernate.MappingException: No persister for:



This can have at least the following reason:
You may forget du add for example HasMany for the persisting class to make a relationship.

 HasMany(x => x.myTableId).KeyColumn("mytableID");


Sunday, September 16, 2012

No message body writer has been found for response class

No message body writer has been found for response class
You need to add the following in maven:



<dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-jaxrs</artifactId>
        <version>1.3.0</version>
</dependency>



Error serializing the response, please check the server logs, response class

Add the following:

              <dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>1.9.9</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-xc</artifactId>
<version>1.9.9</version>
</dependency>

Tuesday, September 11, 2012

Unit test



 [TestMethod]
        public void can_save_and_read_pbentity2()
        {
            object id;

            // Save to database using PbPlatsannonsEntity
            using ( var tx = CurrentSession.BeginTransaction())
            {
                id =
                    CurrentSession.Save(
                        new PbPlatsannonsEntity
                            {   Annonsrubrik = "Rubrik annons",
                                AnnonstextXml = "XML annonstext",
                                AntalPlatser = 12
                               
                            });
                    tx.Commit();
            }
            CurrentSession.Clear();

            //Read from database
            using ( var tx = CurrentSession.BeginTransaction() )
            {
                var pbPlatsannonsEntity = CurrentSession.Get<PbPlatsannonsEntity>(id);
                Assert.Equals("Rubrik annons", pbPlatsannonsEntity.Annonsrubrik);
                Assert.Equals("XML annonstext", pbPlatsannonsEntity.AnnonstextXml);
                Assert.Equals(12, pbPlatsannonsEntity.AntalPlatser);
                //Assert.Equals(new DateTime(2000, 1, 1), pbPlatsannonsEntity.Created);
                tx.Commit();

            }

        }

Tuesday, September 4, 2012

Collections.sort java: sorting java object




//Sort aktlist
final Comparator< aktlist > DATE_ORDER =
                            new Comparator< aktlist >() {
@Override
public int compare( aktlist a1,  aktlist a2) {
   return a2.getDatum().compareTo(a1.getDatum());
}
};
Collections.sort( aktlist , DATE_ORDER);

More information:
http://docs.oracle.com/javase/tutorial/collections/interfaces/order.html

Saturday, August 25, 2012

Android: Preventing destroying the activity when changes made by rotation of the device

Preventing destroying the activity when changes made by rotation of the device, use
android:configChanges="orientation"

Example:


<activity
            android:configChanges="orientation"
            android:name=".QuizStartActivity"
            android:label="@string/title_activity_quiz_start" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>