java - Field not populating from database -
database table
create table wies.department ( dept_id integer not null generated default identity ( start 100, increment 1), dept_nme varchar(20) , sequence_no integer , active_ind char(1) default 'y' );
entity class
@entity @table(name = "department", schema = "wies") public class department implements jpaobjectwithname, serializable { private static final long serialversionuid = 1l; @id @generatedvalue(strategy = generationtype.identity) @column(name = "dept_id", unique = true, nullable = false) private integer departmentid; @column(name = "sequence_no") private int sequence; @column(name = "dept_nme") @size(max = 20, message = "error.department.name.length") private string name; @transient private boolean active; public integer getdepartmentid() { return departmentid; } public void setdepartmentid(integer departmentid) { this.departmentid = departmentid; } public string getname() { return name; } public void setname(string name) { this.name = name; } public int getsequence() { return sequence; } public void setsequence(int sequence) { this.sequence = sequence; } public boolean isactive() { return active; } public void setactive(boolean active) { this.active = active; } @column(name = "active_ind") public string getactivestring() { return booleanutils.tostring(active, "y", "n"); } public void setactivestring(string activestring) { this.active = booleanutils.toboolean(activestring); } @override public string tostring() { return (this.name != null) ? this.name : super.tostring(); } }
dao
@suppresswarnings("unchecked") public list<department> getdepartments() { string jql = "select department a"; query query = entitymanager.createquery(jql + " order a.sequence, a.name"); return (list<department>) query.getresultlist(); }
the generated sql statement console
2014-06-09 16:31:34,282 debug [org.hibernate.sql] - <select department0_.dept_id dept_id1_9_, department0_.dept_nme dept_nme2_9_, department0_.sequence_no sequence3_9_ wies.department department0_ order department0_.sequence_no, department0_.dept_nme>
the select statement missing column active_ind
. how included select statement without adding field in department class populated?
the reason use boolean
field checkbox on form, , storing database needs 'y'
or 'n'
displaying 'y'
or 'n'
in table.
this bit non-elastic, in annotations section before class can add annotation, this:
@entity @table(name = "department", schema = "wies") @where(clause = "active_ind = 'y'" ) public class department implements jpaobjectwithname, serializable { ..... }
in way, records active selected.
Comments
Post a Comment