java - Custom Hibernate insert for collections, counterpart of @WhereJoinTable -


I'm trying to map a relationship with an additional feature (flag) in an additional table, but without I am clearly defining this host table in one unit.

Problem:

Trade has been assigned to 0 or 1 main country, trade is also linked to 0 or more secondary countries.

I have three tables: business , country , business_Country

my business In , I have @WhereJoinTable which works well to get back:

  @OneToOne @JoinTable (name = "business_country", joinColumns = @JoinColumn (name = "business_id"), inverseJoinColumns = @JoinColumn (name = "country_id") @ @jinJinTable (volume = "is_main = 1") private country's main country; @OneToMany @JoinTable (name = "business_country", joinColumns = @JoinColumn (name = "business_id"), inverseJoinColumns = @JoinColumn (name = "country_id")) @WhereJoinTable (section = "is_main = 0") set & Lt; Country & gt; Secondary countries = new hashets & lt; & Gt; ();   

I wonder what would be the equivalent @WhereJoinTable to save.

Simply create a unit business and adding a country to do this gives an infringement violation: ("TESTSCHEMA" "BUSINESS_COUNTRY" "IS_MAIN")

   

What I have to do, is that is_main 1 for main country and is set to for all entries in secondary countries .

I was wondering if any custom @SQLInsert ?

You can use the union table to specify a custom SQL insert statement:
  @OneToOne @JoinTable (name = "business_country", joinColumns = JoinColumn (name = "business_id"), inverseJoinColumns = @JoinColumn (name = "country_id")) @WhereJoinTable (section = "is_main = 1 ") @SQLInsert (SQL =" enter business_country (business_id, country_id, Is_main) value (?,?, 1) ") Country of private country; @OneToMany @JoinTable (name = "business_country", joinColumns = @JoinColumn (name = "business_id"), inverseJoinColumns = @JoinColumn (name = "country_id")) @WhereJoinTable (volume = "is_main = 0") @SQLInsert (SQL = "Business_country (business_id, country_id, is_main) enter value (? in?, 0)") Private set & lt; Country & gt; Secondary countries = new hashets & lt; & Gt; ();   

And the articles can also be useful (note the order of the columns in inserting statements).

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -