Spring JPA @JoinColumn(unique = true) not working -


my entities follows

@entity @table(     name = "t1",     uniqueconstraints = {             @uniqueconstraint(name = "u1", columnnames = {"u1"}),             @uniqueconstraint(name = "u2", columnnames = {"u2_id"}) //this not enforce uniqueness     } ) public class t1 {      @id     @generatedvalue     private long id;      @column(nullable = false)     private string u1; //uniqueness enforced here      @onetoone     @joincolumn(unique = true) //this not enforce uniqueness     private u2 u2;  }  @entity @table(     name = "u2",     uniqueconstraints = {             @uniqueconstraint(name = "p1", columnnames = {"p1"})     } ) public class u2 {      @id     @generatedvalue     private long id;      @column(nullable = false)     private string p1; //uniqueness enforced here  } 

creating , updating entities by

t1 t1_0 = new t1("t1_0"); t1 t1_1 = new t1("t1_1"); u2 u2_0 = new u2("u2_0");  repository.save(t1_0); repository.save(t1_1); repository.save(u2_0);  t1_0 = repository.findone(t1_0.getid()); t1_1 = repository.findone(t1_1.getid());  t1_0.setu2(u2_0); t1_1.setu2(u2_0); 

after transaction finishes t1_0.u2 tied u2_0 , t1_1.u2 tied u2_0. expected throw uniqueness constraint violation exception.

do not understand wrong. other threads on suggest @joincolumn(unique = true) should it.

edit wrapped in 1 transaction

t1_0 = repository.findone(t1_0.getid()); t1_1 = repository.findone(t1_1.getid());  t1_0.setu2(u2_0); t1_1.setu2(u2_0); 

edit2

for reason can't access database either. console view loads after adding password , user blank page shown (some network queries fail).

but can see log foreign keys created , unique constraint aswell

hibernate: alter table driver add constraint uk_ssh305wwvomjtn6opolug33nj unique (cardo_id)  hibernate: alter table car add constraint fkosnia01vhqwmm888uxrg4o6f6 foreign key (manufacturerdo_id) references manufacturer  hibernate: alter table driver add constraint fk3yb5ci9sr6ieo6n4wwwef3puv foreign key (cardo_id) references car 

when adding

my transactions invalid. not see each others data, mistakenly created 1 within another.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -