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