Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating a Key (com.google.appengine.api.datastore.Key) from string

I have a table country in mysql which have fields code(PrimaryKey), offname, actualname all are varchars. I want to create corresponding Entity using JPA

@Entity
public class Country{
       @Id
       private Key code;

    private String offname;
    private String actualname;
}

I want to set the Key my self. I dont want it to be system generated. For this I will have to create Key and set it before I persist the object. Now the problem is how to do I create Key from the string. Can I do something like Key k = new Key("USA"). I do not find such constructor. Please help.

like image 422
FourOfAKind Avatar asked Dec 06 '25 05:12

FourOfAKind


1 Answers

Take a look at the Keyfactory.createKey method. You should be able to do KeyFactory.createKey("Country", "USA");

like image 81
Chris Avatar answered Dec 08 '25 17:12

Chris