Bean Validation problem (Netbeans, Maven, Glassfish, Java EE)

Hi, I have a strange problem. I have a Maven Java Enterprise Application in Netbeans. I have a User.class in the EJB part defined with annotations. In a Useredit window (in the UI part) I use the standart BienFieldGroup binding, the fields are set to setImmediate(true). So when the field loses focus the validation begins, but Glassfish gives the error:


Warning: Failed invoking AtmosphereFramework.doCometSupport()
java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.validator.internal.engine.messageinterpolation.InterpolationTerm
at …

(see the whole error below). The strange thing is:

  • If I leave a field out (value is null) then the validation works when I hit the OK button and I get an error notification and can correct it;
  • If I cange the value of a field and it is “” or an invalid value, I get the error message from Glassfish (and the application tries to load something for infinite time, possibly some hibernate error message).

Since I was confused, I made a vaadin webapplication to test the code and the most interesting parts comes here:

  • If I lunch FIRST the testApp (which starts Glassfish) and SECOND the JavaEEApp (Glassfish is already running) then everything is fine, but
  • If I start FIRST the JavaEEApp (which starts Glassfish) and SECOND the testApp (Glassfish is running already) then both have the same BeanFieldGroup validation error.
  • If I use simple field validation, with
    lastNameField.addValidator(new StringLengthValidator(…
    , then everything is perfect in both cases.

So I think the code must be OK, but something is wrong with the Glassfish loading (I tried to change the hibernate validation in Glassfish, to add it to every part of the JavaEE project, to add every dependency to testApp, but nothing seems to work the same cases remain). I don’t know which part of these project can make the Glassfish loading different. Please help if you have a clue.

User.class is:

[code]
@Entity
@Table(name = “users”)
public class User implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private long id;

@NotNull
@Column(name ="role")
private String role;

@NotNull
@Size(min =2, max = 20)
@Column(name ="firstName")
private String firstName;

@NotNull
@Size(min = 2, max = 20)
@Column(name ="lastName")
private String lastName;
...

[/code]UserEditor and TestApp is using

public class UserEditor extends Window implements Button.ClickListener {

    public static final String ID = "usereditorswindow";

    private final BeanFieldGroup<User> fieldGroup;
...
   @PropertyId("firstName")
    private TextField firstNameField;
    @PropertyId("lastName")
    private TextField lastNameField;
...
        fieldGroup = new BeanFieldGroup<User>(User.class);
        fieldGroup.setBuffered(true);
        fieldGroup.bindMemberFields(this);
        fieldGroup.setItemDataSource(user);
...
        FormLayout details = new FormLayout();
...
        firstNameField = new TextField("First Name");
        firstNameField.setImmediate(true);
        details.addComponent(firstNameField);
...
   @Override
    public void buttonClick(Button.ClickEvent event) {
        if (event.getButton()== ok){
                try {
                    fieldGroup.commit();
...

The whole error message is:

[color=#FF0000]
Warning: Failed invoking AtmosphereFramework.doCometSupport()
java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.validator.internal.engine.messageinterpolation.InterpolationTerm
at org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.interpolateExpression(ResourceBundleMessageInterpolator.java:227)
at org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.interpolateMessage(ResourceBundleMessageInterpolator.java:187)
at org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.interpolate(ResourceBundleMessageInterpolator.java:115)
at org.hibernate.validator.internal.engine.ValidationContext.interpolate(ValidationContext.java:370)
at org.hibernate.validator.internal.engine.ValidationContext.createConstraintViolation(ValidationContext.java:284)
at org.hibernate.validator.internal.engine.ValidationContext.createConstraintViolations(ValidationContext.java:246)
at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateSingleConstraint(ConstraintTree.java:289)
at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:133)
at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:91)
at org.hibernate.validator.internal.metadata.core.MetaConstraint.validateConstraint(MetaConstraint.java:85)
at org.hibernate.validator.internal.engine.ValidatorImpl.validatePropertyForDefaultGroup(ValidatorImpl.java:855)
at org.hibernate.validator.internal.engine.ValidatorImpl.validatePropertyForCurrentGroup(ValidatorImpl.java:768)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateValueInContext(ValidatorImpl.java:725)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateValue(ValidatorImpl.java:184)
at com.vaadin.data.validator.BeanValidator.validate(BeanValidator.java:113)
at com.vaadin.ui.AbstractField.validate(AbstractField.java:969)
at com.vaadin.ui.AbstractField.validate(AbstractField.java:934)
at com.vaadin.ui.AbstractField.getErrorMessage(AbstractField.java:1043)
at com.vaadin.ui.AbstractComponent.beforeClientResponse(AbstractComponent.java:721)
at com.vaadin.ui.AbstractField.beforeClientResponse(AbstractField.java:1706)
at com.vaadin.ui.AbstractTextField.beforeClientResponse(AbstractTextField.java:111)
at com.vaadin.server.communication.UidlWriter.write(UidlWriter.java:98)
at com.vaadin.server.communication.AtmospherePushConnection.push(AtmospherePushConnection.java:166)
at com.vaadin.server.communication.AtmospherePushConnection.push(AtmospherePushConnection.java:144)
at com.vaadin.ui.UI.push(UI.java:1512)
at com.vaadin.server.VaadinSession.unlock(VaadinSession.java:1026)
at com.vaadin.server.VaadinService.requestEnd(VaadinService.java:1355)
at com.vaadin.server.communication.PushHandler.callWithUi(PushHandler.java:299)
at com.vaadin.server.communication.PushHandler.access$200(PushHandler.java:58)
at com.vaadin.server.communication.PushHandler$1.onRequest(PushHandler.java:78)
at org.atmosphere.cpr.AsynchronousProcessor.action(AsynchronousProcessor.java:205)
at org.atmosphere.cpr.AsynchronousProcessor.suspended(AsynchronousProcessor.java:104)
at org.atmosphere.container.GlassFishServ30WebSocketSupport.service(GlassFishServ30WebSocketSupport.java:60)
at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:2075)
at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(DefaultWebSocketProcessor.java:570)
at org.atmosphere.websocket.DefaultWebSocketProcessor$3.run(DefaultWebSocketProcessor.java:332)
at org.atmosphere.util.VoidExecutorService.execute(VoidExecutorService.java:101)
at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(DefaultWebSocketProcessor.java:327)
at org.atmosphere.websocket.DefaultWebSocketProcessor.invokeWebSocketProtocol(DefaultWebSocketProcessor.java:424)
at org.atmosphere.container.GlassFishServ30WebSocketSupport$Grizzly2WebSocketApplication.onMessage(GlassFishServ30WebSocketSupport.java:157)
at org.glassfish.grizzly.websockets.SimpleWebSocket.onMessage(SimpleWebSocket.java:163)
at org.glassfish.grizzly.websockets.frametypes.TextFrameType.respond(TextFrameType.java:68)
at org.glassfish.grizzly.websockets.DataFrame.respond(DataFrame.java:119)
at org.glassfish.grizzly.websockets.BaseWebSocketFilter.handleRead(BaseWebSocketFilter.java:219)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)

Warning: java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.validator.internal.engine.messageinterpolation.InterpolationTerm. Unable to deliver the websocket messages to installed component. Status 500 Message Server Error
[/color]

Do you have different bean validation libraries on you classpath? Glassfish provides one for you so Java EE 6/7 API in provided scope should be enough.

cheers,
matti

Hi, thanks for the replay

First I didn’t add any validation, after the problem I added hibernate (however hibernate 5.0.0.Final is loaded by Glassfish) I tried also with the scope provided annotation in POM, but the problem is the same. As I wrote I made a test application and added ALL the dependencies the JavaEE project has and if I start that project first, that and also the JavaEE project is fine (the only difference that it is a simple vaadin webapp and not a maven javaEE). Moreover without BeanValidation the simple addvalidator with the StringValidators etc. are working fine. (which solves my problem but it is not elegant if we have BeanValidation)

David

Hmm. I have been using Glassfish+BeanValidation+Vaadin, but have never spotted anything like that. Maybe some other dependency is incorrectly pulling in some conflicting validation library? If you have your project sources somewhere I could look at it.

cheers,
matti

I exported the netbeans project an attached it. The EJB bean is in:
QuariumENT\QuariumENT-ejb\src\main\java\com\ecom\quariument\ejb\User.java
The window, which validates it is:
QuariumENT\QuariumENT-ui\src\main\java\com\ecom\quariument\component\UserEditor.java
(which is called by QuariumENT\QuariumENT-ui\src\main\java\com\ecom\quariument\view\admin\AdminView.java)
it is based on Vaadin Dashboard Demo to learn and test different components for a future project.

Thanks
David
20504.zip (228 KB)

Hi,

You app seems to have bit messy build and several problematic dependency problems. It died for me already during deployment due to some guava version conclict errors. You should e.g. never (in Java EE environment) include the validation API in any form. Not even as provided scope as it will come to you along the java-ee API. Also I’m pretty sure you don’t want to include dependency to vaadin-client in you EJB project. vaadin-server maybe, depending a bit what you are doing, but definitely not vaadin-client.

I looked at your User object in the project, and I’m confident that validations in it should work with Vaadin just fine once you’ll get your dependencies set up properly.

cheers,
matti

Thanks Matti,

I will remove the non neccessary dependencies and if it doesn’t solve the problem I will migrate the classes to a new project.

Thanks for your help