You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Pascal Robert <pr...@druide.com> on 2017/05/05 14:10:45 UTC

Duplicate pk when inserting into an empty table

Hi,

I’m using Cayenne 3.1.1 (moving from EOF) for a small project: migration data from FileMaker to MySQL. I have one model with two data maps and two data nodes, one for FileMaker, the other for MySQL. 

Everything works fine, except one thing: 

  java.sql.BatchUpdateException: Duplicate entry '753' for key ‘PRIMARY'

It seems that even if I commit changes after I set the new object, it tries to do a big commit at the end. Code:

    SelectQuery select3 = new SelectQuery(Personnel.class);
    List<Personnel> employes = context.performQuery(select3);
    for (Personnel personnel: employes) {
      Employe employeMySQL = context.newObject(Employe.class);

      if (personnel != null) {
        employeMySQL.setMailing(personnel.getMailing());
        employeMySQL.setPersNom(personnel.getPersNom());
        context.commitChanges();
      }
    }

Personnel being an entity in FileMaker, Employe is the equivalent in MySQL. The primary key in MySQL is an auto_increment field. The PK Generation Strategy is set to Database-Generated. The table in MySQL doesn’t have any data (it was truncated before the inserts). 

Re: Duplicate pk when inserting into an empty table

Posted by Pascal Robert <pr...@druide.com>.
> Le 9 mai 2017 à 04:09, Andrus Adamchik <an...@objectstyle.org> a écrit :
> 
> Hi Pascal,
> 
> Good to see you here! :)
> 
> If you need Cayenne for something bigger, please consider v. 4.0. It will be in Beta very soon, with API and tools (cdbimport specifically) light years ahead of 3.1.

No big need so far, but if we are going to convert the GUI of the FileMaker database, I might use Cayenne more. And I’m using Bootique too :-)

> Andrus
> 
>> On May 5, 2017, at 5:16 PM, Pascal Robert <pr...@druide.com> wrote:
>> 
>> Forget that email. I commented out two other calls to context.commitChanges() in another block, but I was still inserting objects.
>> 
>>> Le 5 mai 2017 à 10:10, Pascal Robert <pr...@druide.com> a écrit :
>>> 
>>> Hi,
>>> 
>>> I’m using Cayenne 3.1.1 (moving from EOF) for a small project: migration data from FileMaker to MySQL. I have one model with two data maps and two data nodes, one for FileMaker, the other for MySQL. 
>>> 
>>> Everything works fine, except one thing: 
>>> 
>>> java.sql.BatchUpdateException: Duplicate entry '753' for key ‘PRIMARY'
>>> 
>>> It seems that even if I commit changes after I set the new object, it tries to do a big commit at the end. Code:
>>> 
>>>  SelectQuery select3 = new SelectQuery(Personnel.class);
>>>  List<Personnel> employes = context.performQuery(select3);
>>>  for (Personnel personnel: employes) {
>>>    Employe employeMySQL = context.newObject(Employe.class);
>>> 
>>>    if (personnel != null) {
>>>      employeMySQL.setMailing(personnel.getMailing());
>>>      employeMySQL.setPersNom(personnel.getPersNom());
>>>      context.commitChanges();
>>>    }
>>>  }
>>> 
>>> Personnel being an entity in FileMaker, Employe is the equivalent in MySQL. The primary key in MySQL is an auto_increment field. The PK Generation Strategy is set to Database-Generated. The table in MySQL doesn’t have any data (it was truncated before the inserts).
>> 
> 


Re: Duplicate pk when inserting into an empty table

Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi Pascal,

Good to see you here! :)

If you need Cayenne for something bigger, please consider v. 4.0. It will be in Beta very soon, with API and tools (cdbimport specifically) light years ahead of 3.1.

Andrus

> On May 5, 2017, at 5:16 PM, Pascal Robert <pr...@druide.com> wrote:
> 
> Forget that email. I commented out two other calls to context.commitChanges() in another block, but I was still inserting objects.
> 
>> Le 5 mai 2017 à 10:10, Pascal Robert <pr...@druide.com> a écrit :
>> 
>> Hi,
>> 
>> I’m using Cayenne 3.1.1 (moving from EOF) for a small project: migration data from FileMaker to MySQL. I have one model with two data maps and two data nodes, one for FileMaker, the other for MySQL. 
>> 
>> Everything works fine, except one thing: 
>> 
>> java.sql.BatchUpdateException: Duplicate entry '753' for key ‘PRIMARY'
>> 
>> It seems that even if I commit changes after I set the new object, it tries to do a big commit at the end. Code:
>> 
>>   SelectQuery select3 = new SelectQuery(Personnel.class);
>>   List<Personnel> employes = context.performQuery(select3);
>>   for (Personnel personnel: employes) {
>>     Employe employeMySQL = context.newObject(Employe.class);
>> 
>>     if (personnel != null) {
>>       employeMySQL.setMailing(personnel.getMailing());
>>       employeMySQL.setPersNom(personnel.getPersNom());
>>       context.commitChanges();
>>     }
>>   }
>> 
>> Personnel being an entity in FileMaker, Employe is the equivalent in MySQL. The primary key in MySQL is an auto_increment field. The PK Generation Strategy is set to Database-Generated. The table in MySQL doesn’t have any data (it was truncated before the inserts).
> 


Re: Duplicate pk when inserting into an empty table

Posted by Pascal Robert <pr...@druide.com>.
Forget that email. I commented out two other calls to context.commitChanges() in another block, but I was still inserting objects.

> Le 5 mai 2017 à 10:10, Pascal Robert <pr...@druide.com> a écrit :
> 
> Hi,
> 
> I’m using Cayenne 3.1.1 (moving from EOF) for a small project: migration data from FileMaker to MySQL. I have one model with two data maps and two data nodes, one for FileMaker, the other for MySQL. 
> 
> Everything works fine, except one thing: 
> 
>  java.sql.BatchUpdateException: Duplicate entry '753' for key ‘PRIMARY'
> 
> It seems that even if I commit changes after I set the new object, it tries to do a big commit at the end. Code:
> 
>    SelectQuery select3 = new SelectQuery(Personnel.class);
>    List<Personnel> employes = context.performQuery(select3);
>    for (Personnel personnel: employes) {
>      Employe employeMySQL = context.newObject(Employe.class);
> 
>      if (personnel != null) {
>        employeMySQL.setMailing(personnel.getMailing());
>        employeMySQL.setPersNom(personnel.getPersNom());
>        context.commitChanges();
>      }
>    }
> 
> Personnel being an entity in FileMaker, Employe is the equivalent in MySQL. The primary key in MySQL is an auto_increment field. The PK Generation Strategy is set to Database-Generated. The table in MySQL doesn’t have any data (it was truncated before the inserts).


Re: Duplicate pk when inserting into an empty table

Posted by Amedeo Mantica <am...@me.com>.
Hi Pascal,
May be related to an issue in pk generation in Cayenne 3.1.1

Could you try with 3.1.2 ? ( you have to compile it, let me know if you have issues )
https://github.com/apache/cayenne/pull/173

Friendly
Amedeo

> On 5 May 2017, at 16:10, Pascal Robert <pr...@druide.com> wrote:
> 
> Hi,
> 
> I’m using Cayenne 3.1.1 (moving from EOF) for a small project: migration data from FileMaker to MySQL. I have one model with two data maps and two data nodes, one for FileMaker, the other for MySQL. 
> 
> Everything works fine, except one thing: 
> 
>  java.sql.BatchUpdateException: Duplicate entry '753' for key ‘PRIMARY'
> 
> It seems that even if I commit changes after I set the new object, it tries to do a big commit at the end. Code:
> 
>    SelectQuery select3 = new SelectQuery(Personnel.class);
>    List<Personnel> employes = context.performQuery(select3);
>    for (Personnel personnel: employes) {
>      Employe employeMySQL = context.newObject(Employe.class);
> 
>      if (personnel != null) {
>        employeMySQL.setMailing(personnel.getMailing());
>        employeMySQL.setPersNom(personnel.getPersNom());
>        context.commitChanges();
>      }
>    }
> 
> Personnel being an entity in FileMaker, Employe is the equivalent in MySQL. The primary key in MySQL is an auto_increment field. The PK Generation Strategy is set to Database-Generated. The table in MySQL doesn’t have any data (it was truncated before the inserts).