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.
Take a look at the Keyfactory.createKey method. You should be able to do KeyFactory.createKey("Country", "USA");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With