Posts

Showing posts from October, 2014

Error while creating hibernate session factory bean

Error Text: Invocation of init method failed; nested exception is org.hibernate.InvalidMappingException: Could not parse mapping document from input stream There are two probable reasons for this situation in my experience. Some of them are as follows 1. The "id" is not present in one or more mapping files (hbm.xml) 2. The DTD definition may be wrong, try replacing following with later. <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 

Java get human understandable time in seconds, minutes, hours & days from milliseconds.

This function returns human readable time from milliseconds. Use this in logging utilities to make sense of time as a common sense. :)  public static final String getHumanRedableTime(long timeInMs) {         String r;         long time = (int) (timeInMs / 1000);         long secs = time % 60 > 0 ? time % 60 : 0;         time = time / 60;         long mins = time % 60 > 0 ? time % 60 : 0;         time = time / 60;         long hours = time % 24 > 0 ? time % 24 : 0;         long days = time / 24;         r = String.valueOf(secs);         String s = secs > 1 ? " seconds " : " second ";         r = r + s;         if (mins > 0) {             String m = (mins > 1) ? " minutes " : " minute ";             r = mins + m + r;         }         if (hours > 0) {             String h = (hours > 1) ? " hours " : " hour ";             r = hours + h + r;         }         if (days > 0) {