java - Custom code generation for JPA entities from database -
i'm here asking simple way add together custom code in jpa entity generated eclipse database.
basically want accomplish add together public string properties containing names of entity properties, , utilize them when need provide "property name" string , sure there won't runtime access errors.
something
@entity @table(name="clients") @namedquery(name="clientmodel.findall", query="select c clientmodel c") public class clientmodel implements serializable { private static final long serialversionuid = 1l; @id @column(name="id_client") private long idclient; public string name; public clientemodel() { } public long getidclient() { homecoming this.idclient; } public void setidclient(long idclient) { this.idclient = idclient; } public string getname() { homecoming this.name; } public void setname(string name) { this.name = name; } //custom code public static final string idclientproperty = "idclient"; public static final string nameproperty = "name"; }
so utilize property name like
clientmodel.nameproperty
and compile-time safe of existence , in case of names refactoring after farther entity generation.
i'm aware of existence of telosys tools & co., hoped there simplier/faster (like custom class provided plugin in wsdl_to_entity generation jaxb)
thank you.
in end i've used telosys tools, if didn't want add together tool project, kinda easy set up, read here https://sites.google.com/site/telosystools/getting-started/21-configure-a-project
in specific case i've added template "jpa_bean_with_links" code during getters creation
#if ( $field.getter ) public static string ${field.getter}property() { homecoming "$field.name"; } #end
java jpa entity
No comments:
Post a Comment