-->
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.  [ 6 posts ] 
Author Message
 Post subject: Validating domain object from xml hbm mapping file ?
PostPosted: Fri Jan 29, 2010 7:11 am 
Beginner
Beginner

Joined: Mon Aug 23, 2004 12:44 am
Posts: 25
We aren't using hibernate validator and annotated domein objects yet.
We are still specifying the mapping in hibernate xml hbm mapping files.

However we are interested in some means to do the following.

Write a Junit test that:
- creates a valid in-memory domain object (not annotated).
- give this object to a validator that validates the object .
- then, in turn, set each of the not-null fields to null and give the object to the validator, to validate that it correctly
validates a not-null field is missing.
However, the validator should "use" the information found in the hibernate hbm mapping files, not in annotations.

Is that possible using the validator ?
Is that possible using another (Hibernate) tool ?

Thanks,
EDH


Top
 Profile  
 
 Post subject: Re: Validating domain object from xml hbm mapping file ?
PostPosted: Fri Jan 29, 2010 11:21 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
You can use Hibernate Validator or Bean Validation without annotations. In this case you need to use xml mapping files. the key is to create validation.xml which will be read by Hibernate Validator at startup time. Via validation.xml you can then point out additional mapping files containing the validator configuration for your classes. You can also pro grammatically configure the mapping files by adding InputStreams to your javax.validation.Configuration when bootstrapping Validator. Configuration contains a addMapping method. This might be more suitable for your unit test scenario. I recommend you have a look at the tests in Hibernate Validator, especially TestUtil
There are also good test in the Bean Validation TCK.
Note, that the Validator configuration files are completely independent from the Hibernate Core configuration files.

--Hardy


Top
 Profile  
 
 Post subject: Re: Validating domain object from xml hbm mapping file ?
PostPosted: Fri Jan 29, 2010 11:28 am 
Beginner
Beginner

Joined: Mon Aug 23, 2004 12:44 am
Posts: 25
Thanks for the tips.
The TestUtil url no longer seems to be valid. Is that link still working for you ?

Regarding "via validation.xml you can then point out additional mapping files". Do you mean you can point out additional hibernate HBM mapping files ?
I guess not and therefore those "additional mapping files" are Validator-specific files ?
Am I right ?
Thanks,
EDH


Top
 Profile  
 
 Post subject: Re: Validating domain object from xml hbm mapping file ?
PostPosted: Fri Jan 29, 2010 11:50 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Sorry, there was a invalid character at the end of the url. It is http://fisheye.jboss.org/browse/Hiberna ... va?r=17911

And yes, validation.xml and the xml files listed in it are Validator specific. That has nothing to do with hbm mappings files.

--Hardy


Top
 Profile  
 
 Post subject: Re: Validating domain object from xml hbm mapping file ?
PostPosted: Mon Feb 01, 2010 4:02 am 
Beginner
Beginner

Joined: Mon Aug 23, 2004 12:44 am
Posts: 25
Thanks. The link now works.

Having read about the validator I'll not be able to use it right now.

As I've wrote, we are currently still using hbm mapping files do describe our ORM, not Hibernate annotations.

I believe the validator only makes sense if the ORM layer is also described using Hibernate annotations.
Using the validator together with hbm mapping files would mean double work no ?
I mean, Hibernate would need the hbm files (which contain field-column not-null constraints and length specifications) to produce the db schema, ánd the validator needs separate validation.xml files (containing the same not-null constraints). Or is Hibernate smart enough to use both the hbm files and the validation files to produce the db schema ?
Testing my domain object using hibernate validator (and validation.xml files) would only test the correctness of my validation rules, not the correctness of my ORM hbm mapping files.

Am I right, or am I overlooking something ?

Thanks,
EDH


Top
 Profile  
 
 Post subject: Re: Validating domain object from xml hbm mapping file ?
PostPosted: Mon Feb 01, 2010 5:36 pm 
Hibernate Team
Hibernate Team

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

I think you are mixing up two orthogonal things. Hibernate Core and ORM mapping and domain model validation via Hibernate Validator.

I don't know what you mean with double work and it makes sense to use Validator even without Annotations.

There are generally two points of contact between Hibernate Core and Validator. First is the generation of database level constraints from your Validator constraints (eg @NotNull). The code which makes this automatically happen lives currently in Hibernate Annotations, but you could just copy the relevant classes into your own project. There is nothing within this code which relies on annotations. In fact you could also just include the Annotations jar into your project to get this schema generation functionality (you don't have to use any annotations).

The second point of contact is the automatic validation of your domain model on session lifecycle events. Again with Annotations you get this out of the box, but you can also write your own event listeners for your case. It's just more work.

Quote:
Testing my domain object using hibernate validator (and validation.xml files) would only test the correctness of my validation rules, not the correctness of my ORM hbm mapping files.

That's correct. Validator is not a tool to check the correctness of your Hibernate mappings. I am not quite sure what you are after here. If your mappings are wrong you will get an error at startup. For developers many IDEs contains some sort of code completion for Hibernate mapping files.

--Hardy


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