java - Auto Increment like with String values in hibernate -
well want know if there appropriate way tackle generating auto id string values, first idea creating auto increment id can call auto_id before saving new entity i'll query latest data inside db id i'll add 1 auto generate value column assign name stringvalue+(id+1) though i'm concerned on how affect performance saving entity needs 2 access in db fetching , saving... question earlier there appropriate way handle scenario?
and sorry english guys if want clarify things question kindly ask, thnx in advance..
here's code attributemodel hibernate annotation
@component @entity @table(name="attribute_info") public class attributemodel { @id @generatedvalue(strategy=generationtype.auto) @column(name="attr_id", nullable=false, unique=true) private int id; @column(name="attr_name") private string name; @column(name="attr_desc") private string desc; @column(name="attr_active") private int active; @column(name="attr_abbr") private string abbr; @onetoone(cascade = cascadetype.all, fetch = fetchtype.eager) @joincolumn(name="stats_id", referencedcolumnname="stats_id") private basestatisticmodel basestats; public string getname() { return name; } public void setname(string name) { this.name = name; } public string getdesc() { return desc; } public void setdesc(string desc) { this.desc = desc; } public int getactive() { return active; } public void setactive(int active) { this.active = active; } public string getabbr() { return abbr; } public void setabbr(string abbr) { this.abbr = abbr; } public basestatisticmodel getbasestats() { return basestats; } public void setbasestats(basestatisticmodel basestats) { this.basestats = basestats; } public int getid() { return id; } public void setid(int id) { this.id = id; } }
i can "don't it". how string id "str10001"
better 10001
? can't optimization strings take more memory , more time. guess need pass string-expecting method later.
if so, pass "str" + id
instead. constructing string on fly surely won't saturate server.
if not, let know you need rather think achieve it.
i'm pretty sure, hibernate can't it. couldn't long time ago checked , makes no sense (in case, it's not feature crowds request).
Comments
Post a Comment