java - JPA 2.0 Eclipse Link -
i have code
@column(updatable=false) @enumerated(enumtype.string) private examtype examtype;
however, can still change value when update via merge. why?
ok. first, if want examtype
column included in sql update
statements, shouldn't mark updatable=false
. being said, appears updatable=false
ignored when not used in combination insertable=false
that's bug in eclipselink (bug 243301), that's not jpa says. set true
or remove it.
secondly, following entity:
@entity public class myentity { @id @generatedvalue private long id; @column(updatable = true) @enumerated(enumtype.string) private examtype examtype; ... }
the following test method runs fine eclipselink:
@test public void testupdateofenum() { myentity e = new myentity(); e.setexamtype(examtype.a); em.persist(e); em.flush(); assertnotnull(e.getid()); assertequals(examtype.a, e.getexamtype()); e.setexamtype(examtype.b); em.merge(e); em.flush(); em.refresh(e); // ensure assert against value read db assertequals(examtype.b, e.getexamtype()); }
below generated sql statements:
insert entitywithenum (id, examtype) values (?, ?) bind => [1, a] update entitywithenum set examtype = ? (id = ?) bind => [b, 1] select id, examtype entitywithenum (id = ?) bind => [1]
honestly, bug on such elementary thing in eclipselink unlikely, more mistake on side if may :)
update: after reading comment op, think got question (which totally unclear honest): op doesn't want examtype
updated exact opposite of initial understanding. op facing bug 243301 (fix released in 2.0.2):
eclipselink allows mappings writable or read-only. mappings marked both insertable=false , updatable=false set read-only.
another workaround described in bug 294803 (that previous 1 duplicates).
Comments
Post a Comment