Question

I'm living in a nightmare, and it is a dependency nightmare ;)

I'm testing an EJB application that uses Hibernate 3.

I deploy it either:

  • On WebSphere 8 (EJB JAR built into an EAR), which is my desired target environment. It works just fine there. As per standards in our organization, (Hibernate) dependencies are taken care of through a separate process. It appears that I'm getting the following Hibernate dependencies there:

    • org.hibernate:hibernate-validator:3.1.0.ga
    • org.hibernate:hibernate-search:3.1.1.ga
    • org.hibernate:hibernate-entitymanager:3.4.0.ga
    • org.hibernate:hibernate-commons-annotations:3.1.0.ga
    • org.hibernate:hibernate-annotations:3.4.0.ga
    • org.hibernate:hibernate-c3p0:3.3.2.ga *
    • org.hibernate:hibernate-core:3.3.2.ga *
    • org.hibernate:hibernate-ehcache:3.3.2.ga *
    • org.hibernate:hibernate-jbosscache:3.3.2.ga *
    • org.hibernate:hibernate-jbosscache2:3.3.2.ga *
    • org.hibernate:hibernate-jmx:3.3.2.ga *
    • org.hibernate:hibernate-oscache:3.3.2.ga *
    • org.hibernate:hibernate-proxool:3.3.2.ga *
    • org.hibernate:hibernate-swarmcache:3.3.2.ga *
  • As an Arquillian test (EJB as a JAR shrinkwrapped in an EAR) that deploys to an embedded JBOSS 7 (jboss.as.jpa.managed=false). It does not work there. I've tried with various sets of dependencies, but this is the minimum set that I know for sure I need:

    • org.hibernate:ejb3-persistence:jar:1.0.2.GA
    • org.hibernate:hibernate-annotations:jar:3.4.0.GA
    • org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final
    • org.hibernate:hibernate-c3p0:3.3.2.ga *
    • org.hibernate:hibernate-core:3.3.2.ga *
    • org.hibernate:hibernate-ehcache:3.3.2.ga *
    • org.hibernate:hibernate-jbosscache:3.3.2.ga *
    • org.hibernate:hibernate-jbosscache2:3.3.2.ga *
    • org.hibernate:hibernate-jmx:3.3.2.ga *
    • org.hibernate:hibernate-oscache:3.3.2.ga *
    • org.hibernate:hibernate-proxool:3.3.2.ga *
    • org.hibernate:hibernate-swarmcache:3.3.2.ga *

This is the error that I'm getting:

java.lang.IllegalArgumentException: Parameter value element [INCLUDED] did not match expected type [org.hibernate.type.EnumType]
    at org.hibernate.ejb.AbstractQueryImpl.validateCollectionValuedParameterMultiBinding(AbstractQueryImpl.java:385)
    at org.hibernate.ejb.AbstractQueryImpl.validateParameterBinding(AbstractQueryImpl.java:363)
    at org.hibernate.ejb.AbstractQueryImpl.registerParameterBinding(AbstractQueryImpl.java:343)
    at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:370)
    at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:67)
    ...

This is the code that I'm executing:

MyStatusEnum[] statuses = ...;
String queryString = "from MyEntity where statusCode in (:statuses)";
Query query = getEntityManager().createQuery(queryString);
query.setParameter("statuses", Arrays.asList(statuses));

The entity field looks like this:

@Column(name="STATUS_CD", nullable=false)
@Enumerated(EnumType.STRING)
public MyStatusEnum getStatusCode() ...

Your help much appreciated!

Was it helpful?

Solution 2

Answering my own question.

So in short, what I was trying to do:

  • Run application on WebSphere which we set up with Hibernate 3
  • Test application on JBOSS 7 which is strongly bound to Hibernate 4
  • Have the container provide the persistence
  • Use a single Hibernate (non-JPA) construct (UserTypes)

When deploying in WebSphere the UserType in the application needed to be compatible with Hibernate 3, and when testing in JBOSS it needed to be compatible with Hibernate 4. As it turns out, the UserType specification had changed just enough for it to be incompatible one way or another. (And if it hadn't it would still have been a bad idea to mix these versions, but it may have taken longer to become apparent.) This mix led to errors such as described in another question. But even with the accepted solution in that question I had a bunch of errors, worked around them with funky dependency management, but always kept having some sort of issue.

If JPA is the contract (between your application and your container) then don't rely on how the container implements that contract (e.g. Hibernate).

If I would provide the persistence from within the application, that'd be an entirely different story.

Sometimes when you're right in the middle of things it's hard to see the big picture :)

OTHER TIPS

This error happened to me too, using Hibernate 5.2.14.Final. Indeed, I suspect that this is due to interaction with some others dependencies inside Glassfish 4.x with additional libraries.

I achieved a solution bypassing the error, replacing @Enumerated(EnumType.STRING) with a attribute converter (implementing javax.persistence.AttributeConverter).

Your mapping will be similar to this after the adjustments:

@Column(name="STATUS_CD", nullable=false)
@Convert(converter = MyStatusEnumConverter.class)
public MyStatusEnum getStatusCode() ...

More information on implementing attribute converters in JPA can be found following this link: https://www.thoughts-on-java.org/jpa-21-how-to-implement-type-converter/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top