参数值元素[...]与预期类型不匹配[org.hibernate.type.EnumType] [英] Parameter value element [...] did not match expected type [org.hibernate.type.EnumType]
问题描述
我正在测试使用Hibernate 3的EJB应用程序。
我正在测试使用Hibernate 3的EJB应用程序。
我部署它:
-
在WebSphere 8上EAR),这是我期望的目标环境。 它在那里工作得很好。按照我们组织中的标准,(Hibernate)依赖关系通过单独的流程来处理。看起来,我在那里得到了下面的Hibernate依赖关系:
-
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
* $作为一个Arquillian测试(将EJB部署为EAR中的JAR)被部署到一个嵌入式JBOSS 7中( //stackoverflow.com/questions/18775632/parent-last-for-hibernate-arquillian-test-on-jboss> -
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:hibe rnate-swarmcache:3.3.2.ga
*
jboss.as.jpa.managed =假
)。 它在那里不起作用。我尝试了各种各样的依赖关系,但这是我知道的最低限度集合,当然我需要:
-
这是我得到的错误:
java.lang.IllegalArgumentException:参数值元素[INCLUDED]没有匹配期望的类型[org.hibernate.type.EnumType]
at org.hibernate.ejb.AbstractQueryImpl.validateCollectionValuedParameterMultiBinding(AbstractQueryImpl.java:385)
at org.hibernate.ejb.AbstractQueryImpl.validateParameterBinding(AbstractQueryImpl。
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)
...
这是我执行的代码:
MyStatusEnum [] statuses = ...;
String queryString =from MyEntity where statusCode in(:statuses);
Query query = getEntityManager()。createQuery(queryString);
query.setParameter(statuses,Arrays.asList(statuses));
实体字段如下所示:
@Column(name =STATUS_CD,nullable = false)
@Enumerated(EnumType.STRING)
public MyStatusEnum getStatusCode()...
您的帮助非常感谢!
所以总之,我正在尝试做什么:
- 在我们使用Hibernate 3设置的WebSphere上运行应用程序
- 测试绑定到Hibernate 4的JBOSS 7上的应用程序
- 使容器提供持久性
- 使用单个Hibernate(非JPA)构造(
UserType
s)
在WebSphere中部署需要与Hibernate 3兼容的应用程序中的 UserType
,并且wh在JBOSS测试中,它需要与Hibernate 4兼容。事实证明, UserType
规范已经发生了变化,仅仅是因为它在某种程度上不兼容。 (如果没有,混合这些版本仍然是一个坏主意,但它可能需要更长的时间才能变得明显。)这种混合导致了错误,如。但即使在这个问题中我接受的解决方案中,我也遇到了一些错误,在时髦的依赖管理环境中解决了这些问题,但始终存在一些问题。
$ b 如果JPA是您的应用程序和您的容器之间的合同,那么不要依赖容器如何实现该合同(如Hibernate)。 如果我要在应用程序中提供持久性,那将是一个完全不同的故事。
有时当你处于正确的事情中时很难看清楚大图:)
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!
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 (
UserType
s)
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 :)
这篇关于参数值元素[...]与预期类型不匹配[org.hibernate.type.EnumType]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!