java - Hibernate - How to set an object which has pk and fk to be VARCHAR in database? -


i have 2 entities, first of is:

@entity @table(name="e_cms_cfg") public class e_cms_cfg extends baseentity{      @id     @onetoone(cascade=cascadetype.all)//, fetch = fetchtype.eager)     @joincolumns({         @joincolumn(name = "cfg_type", nullable = false, referencedcolumnname = "cfg_type", columndefinition = "varchar(32)"),         @joincolumn(name = "cfg_type_id", nullable = false, referencedcolumnname = "id")         })     private e_cms_cfg_type cfgtype; 

the second entity is:

@entity @table(name="e_cms_cfg_type") public class e_cms_cfg_type extends baseentity{      @id     @column(name = "cfg_type", length = 32)     private string cfgtype; 

in first entity, use columndefinition = "varchar(32)" on cfg_type column; however, in database, creating cfg_type integer column. possible create varchar cfg_type column , not integer? , if is, how? using sqlite 3.8.10.1 version.

update: link did not help, if replace in e_cms_cfg @id @naturalid (mutable = false), works, creates without primary key.

you try use natural id annotation here. example:

@naturalid (mutable = false) @column(name = "cfg_type", unique = true, nullable = false, length = 32) private string cfgtype; 

but think still have provide id property , still integer value/column in database.

i think question duplicate of "how use id string type in jpa hibernate"

i hope helps!


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -