Category Archives: Java

Cannot change version of project facet Dynamic Web Module to x.x

1. Problem

When you create maven web project it default using version servlet 2.3. Now you want change servlet 2.5 or 3.0. You come and manual change on web.xml as below

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
          http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">
...

And now your project on eclipse alway has red mark and with problem show error:

Cannot change version of project facet Dynamic Web Module to 3.0.

2. Solution

Right click on project in eclipse project explorer, choose properties-> Project facets-> uncheck on Dynamic Web Module and click  Apply. Right click on project and choose maven-> update project the project will automatic update and resolve above issue.


jsp EL not working

1. Problem

EL expression on JSP page not working

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<body>
<% pageContext.setAttribute("name", "thinh"); %>
<h2>Hello ${name}!</h2>
</body>
</html>

Output become

Hello ${name}!

the content of web.xml

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>SpringMVC4-Hibernate4</display-name>
  <servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/spring/servlet/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
</web-app>

2. Cause

This is cause EL feature not enable on this application. Web servlet 2.3 not enable EL by default.

3. Solution

We have two solutions to solve this issue:

  • Using web servlet 2.5
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  • Enable EL by directive on JSP
<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8" <code>isELIgnored="false"</code>%>

HibernateException: null index column for collection

1. Symtom
When access one-to-many relation with collection mapping by list. You may be get this error

Caused by: org.hibernate.HibernateException: null index column for collection: org.ow2.bonita.runtime.model.Execution.executions

at org.hibernate.persister.collection.AbstractCollectionPersister.readIndex(AbstractCollectionPersister.java:710)

at org.hibernate.collection.PersistentList.readFrom(PersistentList.java:379)

at org.hibernate.loader.Loader.readCollectionElement(Loader.java:1008)

at org.hibernate.loader.Loader.readCollectionElements(Loader.java:646)

at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:591)

at org.hibernate.loader.Loader.doQuery(Loader.java:701)

at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)

at org.hibernate.loader.Loader.loadCollection(Loader.java:1994)

at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)

Continue reading HibernateException: null index column for collection