Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-1757

ServiceBuilder's template for ext-hbm.xml is wrong if you use a Date as a primary key


    • Type: Bug
    • Status: Closed
    • Resolution: Inactive
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
    • Environment:
      Liferay 5.1.1; sorry if this was fixed already in 5.1.2


      In hbm_xml.ftl:

      <id name="${column.name}"
      <#if column.name != column.DBName>

      type="<#if !entity.hasPrimitivePK()>java.lang.</#if>${column.type}">

      <#if column.idType??>
      <#assign class = serviceBuilder.getGeneratorClass("${column.idType}")>

      The code is adding «java.lang.» before the type if the primary key is not a primitive. For instance:

      • String => java.lang.String
      • Long => java.lang.Long
      • Date => java.lang.Date : ERROR! It is java.util.Date

      This creates a wrong ext-hbm.xml and ends up causing strange and useless loading errors when Tomcat is started. For instance this one:

      Loading jar:file:/home/dc/Liferay/liferay-portal-tomcat-6.0-5.1.1/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/portal.properties
      Loading file:/home/dc/Liferay/liferay-portal-tomcat-6.0-5.1.1/webapps/ROOT/WEB-INF/classes/portal-ext.properties
      22/01/2009 18:11:46 org.apache.catalina.core.StandardContext start
      SEVERE: Error listenerStart
      22/01/2009 18:11:46 org.apache.catalina.core.StandardContext start
      SEVERE: Context [] startup failed due to previous errors
      22/01/2009 18:11:46 org.apache.catalina.loader.WebappClassLoader loadClass
      INFO: Illegal access: this web application instance has been stopped already. Could not load org.apache.commons.logging.impl.LogFactoryImpl. The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1246)
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1206)

      (The same, adding more DEBUG info would be

      19:42:13,216 DEBUG [DefaultListableBeanFactory:457] Eagerly caching bean 'liferayHibernateSessionFactory' to allow for resolving potential circular references
      19:42:13,217 DEBUG [DefaultListableBeanFactory:214] Returning cached instance of singleton bean 'liferayDataSource'
      19:42:13,268 DEBUG [DefaultListableBeanFactory:1365] Invoking afterPropertiesSet() on bean with name 'liferayHibernateSessionFactory'
      19:42:14,188 INFO [PortalHibernateConfiguration:730] Building new Hibernate SessionFactory
      22/01/2009 19:42:14 org.apache.catalina.core.StandardContext start
      SEVERE: Error listenerStart
      22/01/2009 19:42:14 org.apache.catalina.core.StandardContext start
      SEVERE: Context [] startup failed due to previous errors
      19:42:14,393 INFO [PortalApplicationContext:816] Closing com.liferay.portal.spring.context.PortalApplicationContext@4dd1b: display name [Root WebApplicationContext]; startup date [Thu Jan 22 19:42:06 CET 2009]; root of context hierarchy

      Note that the java.util. must be also prepended in other places, for example to function parameters in the *Service classes. I had to add the imports for java.util.Date.
      And even if you write java.util.Date in your service.xml, Freemarker fails due to other reasons.

      Of course, using a simple Integer instead of Date as primary key is also a workaround. But this bug is difficult to fix due to the apparently unrelated error messages.





            • Votes:
              0 Vote for this issue
              0 Start watching this issue


              • Created:
                Days since last comment:
                9 years, 27 weeks, 4 days ago


                Version Package