Tag Archives: JPA

Hibernate Search and Glassfish

Using Hibernate Search in combination with Glassfish throws following Exception:

Caused by: org.hibernate.search.SearchException: Trying to use Hibernate Search without an Hibernate EntityManager: class org.eclipse.persistence.internal.jpa.EntityManagerImpl
	at org.hibernate.search.jpa.impl.FullTextEntityManagerImpl.getFullTextSession(FullTextEntityManagerImpl.java:85)
	at org.hibernate.search.jpa.impl.FullTextEntityManagerImpl.getSearchFactory(FullTextEntityManagerImpl.java:109)
	at MyBean.search(MyBean.java:30)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:616)
	at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
	at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
	at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:4154)
	at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5346)
	at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5326)
	at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:214)
	... 58 more

Add an additional


to your persitence.xml in order to use Hibernate JPA for Persistence Management.

Additional information:
Glassfish Application Server does not use Hibernate JPA for Persistence Management (it uses EclipeLink). That’s why Hibernate Search cannot be automatically triggered when reading or writing data to DB.

org.hibernate.MappingException: property mapping has wrong number of columns

When deploying a persistence unit (jar, jar within ear), Exception is thrown:

org.hibernate.MappingException: property mapping has wrong number of columns

Check data types of your Entity Bean, and change any Object to something else, e.g. String

Further information:
Hibernate does not know how to map Object to a valid database type. Do not use Object fields within your Entity Beans.

NoClassDefFoundError while deploying EAR

  • Problem:
    When deploying an EAR (enterprise archive file) to an application server like JBOSS,
    is thrown.
  • Solution:
    Fix your EAR package structure.






    In Eclipse, go to EAR-Project properties, select "Java EE Module Dependencies" and toggle "In Lib Dir" for your shared Java Project

  • Further information:

    • All projects/files have been created with Eclipse
    • application.ear: Exported “Enterprise Application Project”
    • app-ejb.jar: Exported “Enterprise Java Beans Project”
    • app-web.war: Exported “Dynamic Web Project”
    • app-shared.jar: Exported “Java Project”, that contains classes that are used by more than one of the sub-projects. Can also be a third party jar-File with library classes.
    • Exception occurs, since app-web.war or app-ejb.jar may be deployed just before app-shared.jar has been deployed. A workaround for that would be to first deploy app-shared.jar separately and remove it from your enterprise application compilation.

EJB ClassCastException

  • Problem:
    [Ljava.lang.Object; cannot be cast to x.y.z.beanEJB: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to x.y.z.beanEJB
  • Solution:
    Add a "SELECT" statement to your (named) query.
    e.g. change :

    FROM beanEJB e
    INNER JOIN e.tags AS t
    WHERE t LIKE :ttt


    SELECT e FROM beanEJB e
    INNER JOIN e.tags AS t
    WHERE t.string LIKE :ttt

  • Further information:
    A (named) query may return more than one distinct Object. An additional SELECT clause will specify the return type.
  • Code snippets:
    • </named-query>
      <named-query name="namedQuery">
      <![CDATA[SELECT e FROM beanEJB e
      INNER JOIN e.tags AS t
      WHERE t LIKE :ttt]]>

    • Query q = em.createNamedQuery(“namedQuery”);
      q.setParameter(“ttt”, s);