0

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,

Community
  • 1
  • 1
Bob
  • 529
  • 1
  • 7
  • 28
  • `Table 'mam.auto_pk_support' doesn't exist` - check where you are defining the table name. looks to be inccorrect. – petey Jun 12 '17 at 20:36
  • Everything is set in Cayenne and tables names seems to be good. mam is my schema, datainfo is my table name – Bob Jun 12 '17 at 20:45

1 Answers1

1

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.

Nikita
  • 266
  • 2
  • 7
  • Yes, it's intentional, i'm not sure to understand, I want to set an user Id and I set the userIdSelected (it's a java variable) so it's not in Cayenne. userId is already PK and Non null. How should I provide non zero value? – Bob Jun 13 '17 at 14:30
  • I've a relation between my User table and my Date table in cayenne (using the userid in both tables) – Bob Jun 13 '17 at 14:31
  • 1
    If you want to have relation between tables you should use foreign keys not primary keys so I think userid shouldn't be part of PK. And you should use Db\ObjRelatioships in Cayenne that will allow you to use Java objects to bind object together not their ids. As for non-zero value - are you sure you provide value that is not equal to 0 in `userIdSelected`? You may read how to create relationships in Cayenne [here](http://cayenne.apache.org/docs/4.0/tutorial/getting-started-part2.html#d0e202) – Nikita Jun 13 '17 at 15:20