mariadb - Auto generating a String non-primary key value using jpa -
kindly me find out solution problem. have property of type string in entity not primary key. act system generated unique profile id users in project. want auto generate value random string of particular size.
could please me arrive @ solution. have tried @generator , custom id generator class. still null getting inserted field in db.
i using maria db.
hi can use hibernate events.
@postpersist executed after entity manager persist operation executed or cascaded. call invoked after database insert executed.
starting java 5, uuid class provides simple means generating unique ids. identifiers generated uuid universally unique identifiers.
please follow sample example.
public class testmodel { @column("column_name") private string uid; //setter , getter uid @prepersist protected void oncreate() { // set uid setuid(java.util.uuid.randomuuid()); } }
please find below link more information on @prepersist. https://docs.jboss.org/hibernate/entitymanager/3.5/reference/en/html/listeners.html
Comments
Post a Comment