hibernate - many to many and integrity when saving the null -


I have two class software, tags - they are related by many. We can make tags without software.

I want to write a test that checks it:

@Test public make Hansaftveyrvathanultag (void) {< / P>

  list & lt; Tag & gt; Tag = zero; Software software = new software ("software 1", "description1", tag); Try {Software.save (); Failed ("The tag should not be blank"); } Hold (Exceptional) {/ / here never came !!! }}   

Therefore, this test fails. I think it is not a good test for that case - because I can not try to save the data in SOFTWARE_TAG table Of course I manually verify but I want to implement it with hibernate, some annotations or Use something Is this possible? Or how would you do this?

My Institutions

@EntiType Public Category Tag Extension Model {

  public string title; Public tag (string title) {this.title = title; } @ManyToMany (cascade = {CascadeType.ALL}, mapped = "tag" target = Antiti software. Class) public List & lt; Software & gt; Software;   

}

@ Antiti expansion model public class software {

 < Code> public string title; Public string description; @ManyToOne (optional = false) public authors; @ManyToMany (cascade = CascadeType.ALL) @JoinTable (name = "SOFTWARE_TAG", joinColumns = @JoinColumn (name = "Software_id"), inverseJoinColumns = @JoinColumn (name & from = "Tag_id")) public listing lt; Tag & gt; Tag; Public Software (String Title, String Description, Author Writer, List & lt; Tag & gt; Tag) {this.title = title; This.description = Description; this. Author = writer; This tags = tag; }   

}

M are slightly N hibernate " Difficult ", and is not suited for your scenario. I suggest the following:

  • Change the M: N: Relation 1: M in two relays. Software - middle class - tag this way you can add a @Required to the software side and can work with simple 1. M Rels
  • Add some user verification for this

    Remember you keep the current m: n, remember to change your cascade attribute. I would say that now if you remove a software unit, you will remove all the tags related to it (which can be used by other software entities) and cause a mess.

Comments