[Solved] Ebean persistence - compound primary key?

Discussion in 'Plugin Development' started by Xandaros, Nov 13, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Xandaros

    Hey there,
    I am using the built-in Ebean persistence for my plugins, but I cannot figure out how to use a compound primary key.

    I tried it like this:
    Code:
        @Id
        private int x;
        @Id
        private int z;
        //other fields
    
        //Getter/Setter methods
    
    but that just left me with a:
    Code:
    [SQLITE_ERROR] SQL error or missing database (table "Chunks" has more than one primary key)
    
    So... if that is not possible, how do I use compound primary keys, then?


    Got it:
    You create a second class for the key, put the annotation @Embeddable on it, define a hashKey algorithm and overwrite the equals method.
    You then put that class as key into you main class. Instead of @Id, you use @EmbeddedId.

    You have to add both classes to the list in getDatabaseClasses.
     
Thread Status:
Not open for further replies.

Share This Page