Spring, JSR 303 Validation and Hibernate -


I am currently developing an application with Spring using the hibernate as Ober. I know that by default Hibernate uses JSR-303 Bean Validation whenever an entity is stable or loaded. Since this application supports drafts (and I want to get recognition after continuing it) I had to add it firmly. Xml:

  & lt; Validation-mode & gt; No & lt; / Validation-mode & gt;  

The problem with not having these assumptions for hibernate is that when I try to verify verbally on a unit manually (when a draft becomes a document) , The element that is not yet loaded by hibernate (examples of constant bug from the time of validation) are not valid, here is a code example.

Administrator method code:

  @RequestMapping (value = "/ unit / {entity_id}", method = RequestMethod.POST) public string full entity (@pathvirable ("Entity_id ") Long unit_id} {// My antitissivir was autowired in the controller MyEntity myEntity = myEntityService.findById (entity_id); // Here Been Recognition Databinder Bender = NewEntity comes; // validator was also a self-binding binder. Sets volunteer (validator); Binder.validate (); Binding result result = Binder. Babbingircult (); If (result.hasErrors ()) {// handleErrors} // continues the unit, mark the unit as 'not a draft' and continue it ...}  

Ideal Entities Code:

  @Entity @Table (name = "myEntity") Public category MyEntity {@Id @GeneratedValue (strategy = GenerationType.IDENTITY) Private Long ID; @notbank string foo; // Association with bi-directional one-to-many times // Please note the valid annotation, as I want all related bars to be validated // When a MyEntity is valid @Wallid @Outomain (mapped = "My Entity") Private list & lt; Bar & gt; Bars; // Gates and Setters ...} Entity @Table (name = "bar") Public class bar {@Id @GeneratedValue (strategy = GenerationType.IDENTITY) Private Long ID; @notbank string barfu; // Bi-directional multiple-to-one myintimate @ManyToOne Personal MyEntity myEntity; // Getters and Setters ...}  

How can I promote Bean Verification so that whenever a MyEntity instance is valid, all related bars are also valid, without proper verification Firstly, these institutions have to be forced to load.

You can implement a custom and configure Bean Validation to use it Is one.

The default implementation ensures that no objects are loaded from the database (with the assumption that they are successfully validated in the last written form), but you can override for specific associations according to this Requirements.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -