Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8797823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:56:05+00:00 2026-06-13T23:56:05+00:00

The validation works for the front end (jsf). However, it is not getting validated

  • 0

The validation works for the front end (jsf). However, it is not getting validated on prepersist. I’m setting manufacturer to null and it is getting stored in the database as such instead of throwing the constraint violation exception. Thanks.

Here is the relevant part of my entity:

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;


/**
 * The persistent class for the CAR database table.
 * 
 */
@Entity
@Table(name="CAR")
public class Car implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="CAR_ID")
    private int carId;

    @Column(name="MANUFACTURER")
    @NotNull(message = "A manufacturer is required.")
    private String manufacturer;

Here is my persistence.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="src_persistence">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>jdbc/BEAN_VALIDATION_DS</jta-data-source>
        <class>
            xxx.beanvalidation.persistence.Car
        </class>
        <validation-mode>CALLBACK</validation-mode>
        <properties>
            <property name="javax.persistence.validation.mode" value="callback"/>
            <property name="openjpa.Optimistic" value="false"/>
            <property name="openjpa.LockManager" value="none"/>
            <property name="openjpa.jdbc.Schema" value="dbo"/>
            <property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.CMTTransactionFactory" />
            <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect" />
            <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
            <property name="hibernate.current_session_context_class" value="thread" />
            <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider" />
        </properties>
    </persistence-unit>
</persistence>

Here is my DAO:

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import com.westfieldgrp.beanvalidation.persistence.Car;
import com.westfieldgrp.beanvalidation.persistence.Driver;
import com.westfieldgrp.beanvalidation.persistence.Person;
import com.westfieldgrp.common.data.dao.DAOInterface;

public class CarDAO  {

    private EntityManager entityManager;


    public void save(Person convertedPerson, Driver convertedDriver, Car convertedCar) {
        EntityManager em = getEntityManager();
        //convertedPerson.setName(convertedPerson.getName()); // To test JPA validation
        Person savedPerson =  em.merge(convertedPerson);
        convertedDriver.setPersonId(savedPerson.getPersonId());
        Driver savedDriver = em.merge(convertedDriver);
        convertedCar.setDriverId(savedDriver.getPersonId());
        if("test".equals(convertedCar.getManufacturer())){
            convertedCar.setManufacturer(null);// To test JPA validation
        }
        em.persist(convertedCar);
        em.flush();
    }

    public EntityManager getEntityManager() {
            EntityManagerFactory emf = Persistence.createEntityManagerFactory("src_persistence");
            entityManager = emf.createEntityManager();
        return entityManager;
    }

    public void setEntityManager(EntityManager entityManager) {
        this.entityManager = entityManager;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:56:07+00:00Added an answer on June 13, 2026 at 11:56 pm

    Hibernate 3.3 is NOT a JPA2.0 implementation. You need Hibernate >=3.5.1 for JPA2.0.
    There is no integration of the bean-validation API in Hibernate 3.3

    To integrate the bean-validation into hibernate 3.3 you have to implement an BeanValidationEventListener. See the Hibermate implementation as an example:

    https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/cfg/beanvalidation/BeanValidationEventListener.java

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use below jquery.validation to validation email at the front-end. It works fine. jQuery(function(){
As far as I know the System.ComponentModel.DataAnnotations.DataTypeAttribute not works in model validation in MVC
I'm using an awesome plugin to validate my form on the front-end: http://docs.jquery.com/Plugins/Validation .
I used jquery validation for front-end data validate. But i need to do validate
js validation works perfectly when I step through it, but fails at normal speed.
The form validation works fine, so if u leave the email input blank and
I have a form that calls on two separate models. My validation works correctly
I am using the Validation Plugin for jQuery and it works wonders. Except when
I'm using Springs annotations based form validation (mainly @NotBlank and @Length) which works great.
I'm using Thickbox 3.1 with jQuery 1.3.2 with the Validation plugin and all works

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.