-->
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.  [ 2 posts ] 
Author Message
 Post subject: validator don't trigger
PostPosted: Tue Aug 11, 2009 7:13 pm 
Newbie

Joined: Tue Aug 11, 2009 6:28 pm
Posts: 2
hi there, I have the following in the classpath of my project:
Quote:
postgresql-8.3-604.jdbc3.jar
slf4j-simple-1.5.8.jar
hibernate3.jar
antlr-2.7.6.jar
commons-collections-3.1.jar
dom4j-1.6.1.jar
javassist-3.9.0.GA.jar
jta-1.1.jar
slf4j-api-1.5.8.jar
hibernate-commons-annotations.jar
hibernate-validator.jar


I have the following POJO
Code:
public class Flower {
     private long id;
     @Length(min=10,max=255)
     private String name;

     //getters and setters
}


my hibernate.cfg.xml file is
Quote:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost/flowers</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">postgrespostgres</property>
<property name="hibernate.connection.pool_size">1</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.validator.autoregister_listeners">true</property>
<mapping resource="Flower.hbm.xml"/>
</session-factory>
</hibernate-configuration>


it's a simple CRUD project and the persistence works, but the validation doesn't trigger.
the following code doesn't generate any exception, which was supposed to generate because the length of name is less than 10, and the object is persisted inconsistently
Code:
...
Flower f = new Flower();
f.setName("");
session.save(f);
...


what I'm doing wrong here?


Top
 Profile  
 
 Post subject: Re: validator don't trigger
PostPosted: Mon Aug 17, 2009 5:09 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

you don't seem to have the annotation jar in the classpath. This jar contains the code for auto-registration.
Have you tried to manually configure the event listeners?
Code:
<hibernate-configuration>
    <event type="pre-update">
        <listener
          class="org.hibernate.validator.event.ValidateEventListener"/>
    </event>
    <event type="pre-insert">
        <listener
          class="org.hibernate.validator.event.ValidateEventListener"/>
    </event>
</hibernate-configuration>


--Hardy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.