DataNucleus JDO on MySQL fails with FK violation on 1:1 relations -


i have issues persisting simple 2 classes on datanucleus 3.1.3 on mysql, datanucleus seems create invalid foreign-keys, ending in "foreign key constraint fails" -exception database.

here classes:

// datastore since dont care identity here @persistencecapable(identitytype = identitytype.datastore) class {     @persistent     int x;     @persistent     int y; }  // identity type:application here enable id lookups @persistencecapable class b {     @primarykey     @persistent(valuestrategy = idgeneratorstrategy.native)     long id;      @persistent     double longitude;     @persistent     double latitude;     // simple 1:1 unidirectional     @persistent     a; } 

the schematool created tables (innodb) looks good, insert fails, here logs:

12:54:11,369 debug [datanucleus.datastore.native] - insert `a` (`x`,`y`) values (<1>,<1>) 12:54:11,387 debug [datanucleus.datastore.persist] - execution time = 18 ms (number of rows = 1) 12:54:11,398 debug [datanucleus.datastore.persist] - object "foo.a@624af1e" inserted in datastore , given strategy value of "3" 12:54:11,403 debug [datanucleus.datastore] - closing preparedstatement "org.datanucleus.store.rdbms.paramloggingpreparedstatement@6f5ba238" 12:54:11,404 debug [datanucleus.datastore.native] - insert `b` (`longitude`,`latitude`,`a_a_id_oid`) values (<0.5099776394799052>,<0.6191090630996077>,<51>) 12:54:11,419 warn  [datanucleus.datastore.persist]  ... cannot add or update child row: foreign key constraint fails (`xperimental`.`b`, constraint `b_fk1` foreign key (`a_a_id_oid`) references `a` (`a_id`)) 

looking @ logs on lines (3) , (5) suspicious insert table returned pk of "3" datanucleus instead uses value of "51" fk on when inserting data table b causes violation.

where issue? thanks

update: resources

class a

package jdotest.a;  import javax.jdo.annotations.identitytype; import javax.jdo.annotations.persistencecapable; import javax.jdo.annotations.persistent;  @persistencecapable(identitytype = identitytype.datastore) public class {   @persistent   private int x;   @persistent   private int y;    public int getx() {     return x;   }    public int gety() {     return y;   } } 

class b

package jdotest.b;  import javax.jdo.annotations.idgeneratorstrategy; import javax.jdo.annotations.persistencecapable; import javax.jdo.annotations.persistent; import javax.jdo.annotations.primarykey;  import jdotest.a.a;  @persistencecapable public class b {   @primarykey   @persistent(valuestrategy = idgeneratorstrategy.native)   long   id;    @persistent   double longitude;   @persistent   double latitude;   // simple 1:1 unidirectional   @persistent        a;    public long getid() {     return id;   }    public double getlongitude() {     return longitude;   }    public double getlatitude() {     return latitude;   }    public void seta(a a) {     this.a = a;   }    public geta() {     return a;   } } 

dao

package dao; import javax.jdo.jdohelper; import javax.jdo.persistencemanager; import javax.jdo.persistencemanagerfactory; import javax.jdo.transaction;  import jdotest.b.b;  public class bdao {   public void write(b b) {     persistencemanagerfactory pmf = jdohelper.getpersistencemanagerfactory("cloud-sql");     persistencemanager pm = pmf.getpersistencemanager();     transaction tx = pm.currenttransaction();     try {       tx.begin();       pm.makepersistent(b);       tx.commit();     } {       if (tx.isactive())         tx.rollback();       pm.close();     }   } } 

execution

  package exec;    import jdotest.a.a;   import jdotest.b.b;   import dao.bdao;    public class ex{     public void persist(){       a = new a();       b b = new b();       b.seta(a);       new bdao().write(b); //<-- exception     }   }     
  • the exception *

    java.sql.sqlexception: cannot add or update child row: foreign key constraint fails (xperimental.b, constraint b_fk1 foreign key (a_a_id_oid) references a (a_id))


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -