-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 posts ] 
Author Message
 Post subject: javax.persistence.validation.factory cast issue
PostPosted: Mon Feb 07, 2011 12:36 pm 
Newbie

Joined: Mon Feb 07, 2011 12:21 pm
Posts: 8
Hello,

I try to bootstrap my own implementation of ValidatorFactory in JBoss 6.0.0.final (hib 3.6.0.Final) through the jpa 2 standard property javax.persistence.validation.factory. Maybe it's me but this line of code will always throw a ClassCastException as the property evaluated resolves to a String:

Code:
at org.hibernate.cfg.beanvalidation.BeanValidationActivator.applyDDL(BeanValidationActivator.java:118) [:3.6.0.Final]
   ... 73 more
Caused by: org.hibernate.HibernateException: Property javax.persistence.validation.factory should contain an object of type javax.validation.ValidatorFactory
   at org.hibernate.cfg.beanvalidation.TypeSafeActivator.getValidatorFactory(TypeSafeActivator.java:335) [:3.6.0.Final]
   at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyDDL(TypeSafeActivator.java:106) [:3.6.0.Final]
   ... 78 more


Top
 Profile  
 
 Post subject: Re: javax.persistence.validation.factory cast issue
PostPosted: Tue Feb 08, 2011 6:20 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
I would assume that your custom implementation implements ValidatorFactory as well, right? If so it should work. Is this the full stacktrace? And how does your custom code look like?

--Hardy


Top
 Profile  
 
 Post subject: Re: javax.persistence.validation.factory cast issue
PostPosted: Tue Feb 08, 2011 11:39 am 
Newbie

Joined: Mon Feb 07, 2011 12:21 pm
Posts: 8
Thanks Hardy. Please check this line of code which is called by this one in my case. What I say is the line
Code:
ValidatorFactory.class.cast( "my.custom.ValidatorFactory" )
will always throw a ClassCastException. What do you think?


Top
 Profile  
 
 Post subject: Re: javax.persistence.validation.factory cast issue
PostPosted: Tue Feb 08, 2011 11:56 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
If you pass a string, but the whole point is that you should have an actual instance in the map. The spec says "In Java EE environments, a ValidatorFactory instance is made available by the Java EE..."
You are not supposed to pass the fully qualified class name as string. Does this make sense or are we still talking about something else?

--Hardy


Top
 Profile  
 
 Post subject: Re: javax.persistence.validation.factory cast issue
PostPosted: Tue Feb 08, 2011 12:16 pm 
Newbie

Joined: Mon Feb 07, 2011 12:21 pm
Posts: 8
That's the whole point I'd love to have an instance of my class in the map but I don't call this code directly. As a client the only thing I do is configure the persistence.xml:

Code:
<property name="javax.persistence.validation.factory"   value="my.custom.ValidatorFactory" />


On deploying the pu, the private method is called by TypeSafeActivator.applyDDL passing an instance of java.util.Properties....So when the value is retrieved from the Map the only resulting object class we can get is a java.lang.String which is incompatible with ValidatorFactory...


Top
 Profile  
 
 Post subject: Re: javax.persistence.validation.factory cast issue
PostPosted: Tue Feb 08, 2011 1:31 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
I think here is the problem. This is not a property to be set in persistence.xml. It's a programmatic thing the container used via createContainerEntityManagerFactory(PersistenceUnitInfo, Map)

Do you really need a custom ValidatorFactory? What use case do you try to solve?

I think AS 6 has a configuration file bv-core-jboss-beans.xml where the factory is specified. That might be the way to go.

--Hardy


Top
 Profile  
 
 Post subject: Re: javax.persistence.validation.factory cast issue
PostPosted: Tue Feb 08, 2011 2:41 pm 
Newbie

Joined: Mon Feb 07, 2011 12:21 pm
Posts: 8
Wow, this is subtle. The UC I try to solve is to be able to have my ConstraintValidator being CDInjectable.
Thanks again for the explanation.


Top
 Profile  
 
 Post subject: Re: javax.persistence.validation.factory cast issue
PostPosted: Tue Feb 08, 2011 4:05 pm 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
The UC of injecting dependencies into validator implementations is one of the issues addressed by the Seam Validator module:

https://github.com/seam/validation

This is currently work in progress, but maybe you would like to give it a try. I'd be more than interested in you feedback :-)

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
 Post subject: Re: javax.persistence.validation.factory cast issue
PostPosted: Tue Feb 08, 2011 4:19 pm 
Newbie

Joined: Mon Feb 07, 2011 12:21 pm
Posts: 8
Thanks Gunnar, I will.


Top
 Profile  
 
 Post subject: Re: javax.persistence.validation.factory cast issue
PostPosted: Wed Feb 09, 2011 9:16 am 
Newbie

Joined: Mon Feb 07, 2011 12:21 pm
Posts: 8
Gunnar,

I installed seam-validation in server/default/lib of jboss6 (just like I did for seam-solder) in order to run my Integration test with arquillian without the need to specify all classes/resources on the deployed archive ( I used the aquillian-jboss6-remote connector).
When I run my integration test I've got this error:

Code:
2011-02-09 08:08:29,646 INFO  [org.jboss.weld.Version] (WorkerThread#0[127.0.0.1:41563]) WELD-000900 1.1.0 (CR3)
2011-02-09 08:08:30,131 DEBUG [org.jboss.weld.Bootstrap] (WorkerThread#0[127.0.0.1:41563]) WELD-000103 Enabled alternatives for Manager
Enabled alternatives: [] []
Registered contexts: [interface javax.enterprise.context.Dependent, interface javax.inject.Singleton, interface javax.enterprise.context.SessionScoped, interface javax.enterprise.context.RequestScoped, interface javax.enterprise.context.ApplicationScoped, interface javax.enterprise.context.ConversationScoped]
Registered beans: 0
Specialized beans: 0
: [] []
2011-02-09 08:08:30,131 DEBUG [org.jboss.weld.Bootstrap] (WorkerThread#0[127.0.0.1:41563]) WELD-000104 Enabled decorator types for Manager
Enabled alternatives: [] []
Registered contexts: [interface javax.enterprise.context.Dependent, interface javax.inject.Singleton, interface javax.enterprise.context.SessionScoped, interface javax.enterprise.context.RequestScoped, interface javax.enterprise.context.ApplicationScoped, interface javax.enterprise.context.ConversationScoped]
Registered beans: 0
Specialized beans: 0
: []
2011-02-09 08:08:30,131 DEBUG [org.jboss.weld.Bootstrap] (WorkerThread#0[127.0.0.1:41563]) WELD-000105 Enabled interceptor types for Manager
Enabled alternatives: [] []
Registered contexts: [interface javax.enterprise.context.Dependent, interface javax.inject.Singleton, interface javax.enterprise.context.SessionScoped, interface javax.enterprise.context.RequestScoped, interface javax.enterprise.context.ApplicationScoped, interface javax.enterprise.context.ConversationScoped]
Registered beans: 0
Specialized beans: 0
: []
2011-02-09 08:08:30,155 ERROR [org.jboss.kernel.plugins.dependency.AbstractKernelController] (WorkerThread#0[127.0.0.1:41563]) Error installing to Create: name=vfs:///home/franck/jboss-6.0.0.Final/server/default/deploy/test.war_WeldBootstrapBean state=Configured: java.lang.NullPointerException
   at org.jboss.weld.util.ApiAbstraction.annotationTypeForName(ApiAbstraction.java:86) [:6.0.0.Final]
   at org.jboss.weld.ejb.EJBApiAbstraction.<init>(EJBApiAbstraction.java:36) [:6.0.0.Final]
   at org.jboss.weld.bootstrap.BeanDeployment.<init>(BeanDeployment.java:99) [:6.0.0.Final]
   at org.jboss.weld.bootstrap.WeldBootstrap$DeploymentVisitor.visit(WeldBootstrap.java:184) [:6.0.0.Final]
   at org.jboss.weld.bootstrap.WeldBootstrap$DeploymentVisitor.visit(WeldBootstrap.java:195) [:6.0.0.Final]
   at org.jboss.weld.bootstrap.WeldBootstrap$DeploymentVisitor.visit(WeldBootstrap.java:155) [:6.0.0.Final]
   at org.jboss.weld.bootstrap.WeldBootstrap.startContainer(WeldBootstrap.java:286) [:6.0.0.Final]
   at org.jboss.weld.integration.deployer.env.helpers.BootstrapBean.initialize(BootstrapBean.java:106) [:6.0.0.Final]
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_18]
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_18]


If I remove seam-validation.jar from the default server lib, I don't have the issue anymore. Did you try to deploy seam-validation in jboss6 with such a scenario? (BTW I quickly browse through the code and this is exactly what I need, method validation etc..).


Top
 Profile  
 
 Post subject: Re: javax.persistence.validation.factory cast issue
PostPosted: Wed Feb 09, 2011 7:46 pm 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
No, I haven't deployed Seam Validation to JBoss AS yet. I have tried it on GF v3, this worked out fine. I deployed SV within the application WAR instead of adding the JAR to the server's libs though, you might try this as well.

Does the problem only occur when you run a remote test with Arquillian or also when you deploy a standard WAR on the server?

The best is you create a JIRA ticket for this (if possible with a reproducible test case, setup description etc.). You got the pleasure to create the first ticket in https://issues.jboss.org/browse/SEAMVALIDATE at all :) Interpreting your stacktrace this might also be in issue with Weld itself, as NPEs are never a good sign.

Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.