I once came across a validation framework for java, where you wrote one method that protected the integrity of the data-type and any CRUD operations on that data-type automatically called this method.
Does anyone know what this framework is? I simply want to avoid repetitive validation on every CRUD method attached to a data-type.
Here's a huge list of Java Validation Libraries / Frameworks - http://java-source.net/open-source/validation
Apache Commons has a validation framework.
Are you using Hibernate for persistence? If you are, there is Hibernate Validator.
Spring has a very nice validation and binding API.
Hibernate Validator, per adref's answer, is an implementation of JSR-303. Here's a helpful article to get you started if you are interested:
http://java.dzone.com/articles/bean-validation-and-jsr-303
Related
I work on an application that uses Spring MVC and Hibernate. I am implementing some RESTful web services and am curious how to easily filter collections server side.
As an example, I want to be able to filter a collection of employee entities. I have researched several options, such as RQL, the way Google handles custom searches, Ebay's answer, and even Yahoo's YQL. They all seem to be good answers to the filtering question, but I can not seem to find any libraries that will allow me to easily implement this concept.
I did find here, that:
Apache CXF introduced FIQL support with its JAX-RS implementation since 2.3.0 release
but we are already using Spring MVC.
I'm surprised there is no library for taking the bold query string below, for example, and translating that into SQL or something that Hibernate can use to filter.
/employees?lastname=john OR jon&hiredate lt 20010201
It is entirely possible that I am thinking of this incorrectly, but I wanted to tap into the community's experience and knowledge. What am I missing?
I know this is old, but for completeness, there are at least two libraries that handle parsing RQL:
https://github.com/jazdw/rql-parser
https://github.com/jirutka/rsql-parser (not quite RQL by default, but configurable)
I'm using jazdw/rql-parser myself and started working on an SQL mapper but as Oleksi mentioned there is a lot of custom code required for validating, field mapping, etc. so I don't know how generic I can make it yet.
A library that directly converts a GET like that into SQL could be very insecure. You need to have an intermediate layer to do some validation to make sure that the user isn't messing with the URL to execute a SQL injection.
As far as I know, the best you can do is use your JAX-RS implementation to cleanly read in those query parameters, validate them, and use something like a prepared SQL statement to securely execute them.
From what I see in ormlite it has implemented its annotations as well as JPA standard annotations. First of all, what was the reason of designing new set of annotations?
Secondly, how one can use standard annotation like #Entity, etc instead of ormlite specific annotations. Right now, I am getting not defined error for those entities. Do I need a jar file?
#DataNucleus is correct. ORMLite is not a fully compliant JPA implementation. There are many features of ORMLite that do not map well with the JPA annotations and it was easier to create my own set. JPA is also a very large specification and I didn't want a large percentage of the annotations to generate UnsupportedOperationException or jut fail quietly. Lastly, I was trying to write a ORM library with 0 dependencies.
All that said, I am interested in improving ORMLite's JPA compatibility so if you have any suggestions on how to make it better, please send them to the developers mailing list. I'd love to improve it.
Because it isn't a real JPA implementation, and just makes use of JPA annotations for convenience. Obviously, by using it, you lose the portability offered by JPA itself, but then it may have some advantages for very specific situations
we want to do business rule validation outside our java code using some xml etc.we are using Spring 3.1 and JSF 2.0.i tried to search but cudn't found concrete on placing business rule outside our java code.i will thankful if someone can provide direaction for this
I know this isn't exactly what you are looking for but you can use Hibernate annotations in place of hard coded validators in JSF 2.
These are just a few examples of this.
http://weblogs.java.net/blog/urubatan/archive/2006/09/aspectj_hiberna.html
http://docs.jboss.org/seam/1.1GA/reference/en/html/validation.html
I'm wanting using JPA in ear project. Development project must be started ASAP so I have not a lot of time to research and investigate. Could you say please JPA API is restricted functionality of Hibernate or no. At this moment I'm using Hibernate directly. For example in future I'm planing to use hibernate-search and maybe hibernare-validate and -shard. Can I be sure that in future I will not have problem with using this.
And one more example - can I use HAR archive and JPA together.
Why JPA? For project will available RESTful service (jersey or resteassy implementation). And as I looked in much case using JPA for this. I'm a newbie in this so it's only my IMHO. May be i mistakes.
Thanks a lot.
Best regards
Artem
JPA is a subset of hibernate, but you're not limited to it. If you need a hibernate specific feature, you can generally use it at the cost of being tied to hibernate. For example, we've mixed in hibernate annotations with JPA ones, including the validater ones, without trouble.
JPA in theory lets you change the persistance provider later.
Sticking to only JPA compatible configuration can cause more trouble that is solved by the dubious promise of seamlessly swapping providers however.
I would like to use hibernate for persisting objects through web services and am thinking of using hyperjaxb3 with Apache CXF. Do you have any other suggestion for this purpose?
Edit: To clarify my question a little bit... I am using eclipse and wsgen, wsimport ant tasks to generate my service and client classes respectively. I am using annotations to configure entities which are persisted by hibernate. With this setting I encountered a few simple issues which I was able to fix by googling around. Then I encountered a problem with cyclic references which I fixed with afterUnmarshal (described here ). Afterwards I encountered a problem of entity with two parents (two bidirectional relationships) which I tried to solve with #XmlID and #XmlIDREF in the way described here but didn't make it in the end. And at that time I began to wonder if I am doing something wrong and should use different tools/technologies (should I maybe switch to maven, or introduce spring, etc.) so I investigated a little bit and found out about hyperjaxb3 and am wondering if that could be the solution to my problems? :)
Edit 2: In short, which way you use, prefer or just do in most cases involving these two?
EclipseLink JAXB (MOXy) has extensions for handling JPA entities, for more information see:
http://wiki.eclipse.org/EclipseLink/Examples/MOXy/JPA
Take a look the Spring MVC Tutorial, which you'd be able to integrate with Hibernate quite easily.