Search code examples
mysqljakarta-eevaadinapache-cayenne

Error table.auto_pk_support when I try to save a value in my table


I've another issue (seems to be the same thing as : stored procedure 'auto_pk_for_table' not found) But I put auto-increment and unique index for the ID and 'Database-Generated' in the primary key with my auto-increment field, See :

public abstract class _DateInfo extends CayenneDataObject {

    public static final String ENDDATETIME_PROPERTY = "enddatetime";
    public static final String STARTDATETIME_PROPERTY = "startdatetime";
    public static final String USER_ID_PROPERTY = "userId";

    public static final String DATEINFOID_PK_COLUMN = "DATEINFOID";
    public static final String USERID_PK_COLUMN = "USERID";

    public void setEnddatetime(Date enddatetime) {
        writeProperty(ENDDATETIME_PROPERTY, enddatetime);
    }
    public Date getEnddatetime() {
        return (Date)readProperty(ENDDATETIME_PROPERTY);
    }

    public void setStartdatetime(Date startdatetime) {
        writeProperty(STARTDATETIME_PROPERTY, startdatetime);
    }
    public Date getStartdatetime() {
        return (Date)readProperty(STARTDATETIME_PROPERTY);
    }

    public void setUserId(int userId) {
        writeProperty(USER_ID_PROPERTY, userId);
    }
    public int getUserId() {
        Object value = readProperty(USER_ID_PROPERTY);
        return (value != null) ? (Integer) value : 0;
    }
}

I tried to save a local time when I click on the save button :

    Button save = new Button("Save", event -> {
    DateInfoFactory date = CayenneUtil.getContext().newObject(
            DateInfoFactory.class);

        date.setUserId(userIdSelected);
        if (startTime.getValue() != null) {
            LocalTime startDate = startTime.getValue();
            date.setStartdatetime(toDate(startDate));
        }

        date.getObjectContext().commitChanges();

    });
    save.addStyleName(ValoTheme.BUTTON_PRIMARY);

But then, I received this error :

juin 12, 2017 9:38:32 PM org.apache.cayenne.log.CommonsJdbcEventLogger logQuery
INFOS: LOCK TABLES AUTO_PK_SUPPORT WRITE
juin 12, 2017 9:38:32 PM org.apache.cayenne.log.CommonsJdbcEventLogger logQuery
INFOS: UNLOCK TABLES
juin 12, 2017 9:38:32 PM com.vaadin.server.DefaultErrorHandler doDefault
GRAVE: 
org.apache.cayenne.CayenneRuntimeException: [v.4.0.M5 Feb 24 2017 07:47:55] Commit Exception
..
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'mam.auto_pk_support' doesn't exist

My table in MySQL is : enter image description here

What should I do?

Thanks,


Solution

  • There can be several options how you can fix your code.

    1. You have compound PK (dateinfoid + userid) is this intended? Probably you should use single column PK (i.e. only dateinfoid) as it's uniquely identifies objects in your case and potentially will save you from other troubles.

    2. If compound PK is intentional then make sure you provide non zero value in userIdSelected or otherwise Cayenne will try to provide it via auto_pk_support table.