Tuesday, January 22, 2013

How to get process id by port number at mac OSX

When some application listening on some port it could be problem to find out which application it is. On mac OSX is problem to get process id by port number because following command doesn't work:
netstat -p
Mac OSX 10.8 and earlier doesn't support switch '-p' in netstat command. However there is simple workaround. There is command 'lsof' which list open files and their process ids. You can list processes which are listening like this:
lsof -i | grep LISTEN
It's useful to see port number instead of service name running on such port. It's better to see :8080 instead of 'http-alt'. It could be done like this:
lsof -i -P | grep LISTEN

Friday, January 18, 2013

Hibernate inconsistent mapping problem

I met following exception during changing hibernate mapping. I'm using hibernate 3.2

Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: cz.koroptev.cubiculus.core.model.Brick column: id_shape (should be mapped with insert="false" update="false")
 at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:605)
 at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:627)
 at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:645)
 at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:420)
 at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
 at org.hibernate.cfg.Configuration.validate(Configuration.java:1026)
 at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1211)
 at cz.koroptev.cubiculus.core.services.impl.HibernateManagerServiceImpl.(HibernateManagerServiceImpl.java:28)
 ... 47 more
Problem was in inconsistent mapping of relations ship between objects 'Shape' and 'Brick'. Object 'Shape' contain set of bricks mapped as:
  <set name="bricks" lazy="true" order-by="id_brick" >
   <key column="id_shape" not-null="true" />
   <one-to-many class="Brick" />
  </set>
and 'Brick' contains mapping to 'Shape'
  <many-to-one name="shape" class="Shape" column="id_shape"
   foreign-key="brick_shape" not-null="false" />
Problem is that in first mapping is column 'id_shape' mapped as not-null="true" and in second is mapped as not-null="false". This lead to mentioned exception.

Tapestry 5 Exception - missing template

Following error appears in application production log:
TP-Processor19 2013.01.17.21.00.08 ERROR core.services.AppModule.extendedRequestExceptionHandler - Processing of request failed with uncaught exception: Embedded component(s) discussion, layout are defined within component class cz.koroptev.cubiculus.core.pages.buildinginstruction.BuildingInstructionLego (or a super-class of BuildingInstructionLego), but are not present in the component template (null).
org.apache.tapestry5.ioc.internal.OperationException: Embedded component(s) discussion, layout are defined within component class cz.koroptev.cubiculus.core.pages.buildinginstruction.BuildingInstructionLego (or a super-class of BuildingInstructionLego), but are not present in the component template (null).
 at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.logAndRethrow(OperationTrackerImpl.java:121)
 at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:88)
 at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87)
 at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1121)
 at org.apache.tapestry5.internal.pageload.PageLoaderImpl.createAssembler(PageLoaderImpl.java:221)
 at org.apache.tapestry5.internal.pageload.PageLoaderImpl.getAssembler(PageLoaderImpl.java:211)
 at org.apache.tapestry5.internal.pageload.PageLoaderImpl$3.invoke(PageLoaderImpl.java:183)
 at org.apache.tapestry5.internal.pageload.PageLoaderImpl$3.invoke(PageLoaderImpl.java:178)
 at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:74)
 at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87)
 at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1121)
 at org.apache.tapestry5.internal.pageload.PageLoaderImpl.loadPage(PageLoaderImpl.java:177)
 at $PageLoader_69b95d11058ab2.loadPage(Unknown Source)
 at org.apache.tapestry5.internal.services.PageSourceImpl.getPage(PageSourceImpl.java:104)
 at $PageSource_69b95d11058aa7.getPage(Unknown Source)
 at org.apache.tapestry5.internal.services.NonPoolingRequestPageCacheImpl.get(NonPoolingRequestPageCacheImpl.java:82)
 at $RequestPageCache_69b95d11058aa6.get(Unknown Source)
 at $RequestPageCache_69b95d11058aa3.get(Unknown Source)

Strange exception in other words say that it's not possible to find application template for some component. This problem shows just at production server not at my development machine. I'm using Tapestry 5 version 5.3.2.

After some time I found that problem was in directory naming. Templates in maven project are in directory 'src/main/webapps/buildinInstruction'. Name 'buildinInstruction' contains upper case I. When I change it to lower case problem disappears. Problem can't be reproduced at my machine because my Mac OS X use case insensitive file system.