how to implements find() or findById() methods for embeddedId in Play framework
I have worked with play framework lately for creating project, thanks you so much for my friends in this forum for your assist. Now days i have a problem in play again. I have some model classes that having unique id (not incremental/default id), thereby i extend GenericModel than Model in my Model class. I feel confuse how to use GenericMOdel's find() or findById() methods for EmbeddedId field. This is my snippet codes:
Models class 1:
@Entity
@Table(name="DATKAPJMLPST")
public class Datkapjmlpst extends GenericModel {
//private static final long serialVersionUID = 1L;
@EmbeddedId
public DatkapjmlpstPK id;
@Column(name="BIAYAKAP")
public BigDecimal biayakap;
@Column(name="BPJ")
public BigDecimal bpj;
@Temporal( TemporalType.DATE)
@Column(name="DtProses")
public Date dtProses;
public String flag;
@Column(name="JmlPstKom")
public BigDecimal jmlPstKom;
@Column(name="JmlPstSos")
public BigDecimal jmlPstSos;
@Column(name="JmlPstTotal")
public BigDecimal jmlPstTotal;
@Column(name="KdDati2")
public String kdDati2;
//@Column(name="KdKC")
@ManyToOne
@JoinColumn(name="KDKC")
public Refkc refKC;
@Column(name="NOREG")
public String noreg;
public Datkapjmlpst() {
}
}
Model class 2:
@Embeddable
public class DatkapjmlpstPK extends GenericModel {
//default serial version id, required for serializable classes.
//private static final long serialVersionUID = 1L;
@Temporal(TemporalType.DATE)
@Column(name="Bln")
public Date bln;
//@Column(name="KdPPK")
@ManyToOne
@JoinColumn(name="KdPPK")
public Refppk refPPK;
@Column(name="KdBU")
public String kdBU;
public DatkapjmlpstPK() {
}
}
Controller's method:
public static void show(Date bln, String kdppk, String kdbu) {
JPAQuery datkapjmlpst = Datkapjmlpst.find("SELECT d FROM Datkapjmlpst d " +
"WHERE d.id.bln=? AND d.id.refPPK.kdppk=? AND d.id.kdBU=?", bln, kdppk, kdbu);
render(datkapjmlpst, bln, kdppk, kdbu);
}
Views :
#{form @edit(datkapjmlpst.id.bln, datkapjmlpst.id.refPPK.kdppk, datkapjmlpst.id.kdBU)}
<p>
<strong>Tanggal:</strong> ${datkapjmlpst.bln?.format('dd-MM-yyyy')}
</p>
<p>
<strong>Kantor Cabang:</strong> ${datkapjmlpst.refKC.nmkc}
</p>
<p>
<strong&g开发者_StackOverflow社区t;BPJ:</strong> ${datkapjmlpst.bpj}
</p>
<p>
<strong>Jml Peserta Sosial:</strong> ${datkapjmlpst.jmlPstSos}
</p>
<p>
<strong>Status:</strong> ${datkapjmlpst.flag}
</p>
<p class="buttons">
<input type="submit" value="Edit Kapitasi"> <a href="@{index()}">Back to search</a>
</p>
#{/form}
These code has an error output like this :
Internal Server Error (500) for request GET /kapitasi/show? kdbu=00000000&kdppk=00080001&bln=2011-04-01
Template execution error (In /app/views/Kapitasi/show.html around line 5)
Execution error occured in template /app/views/Kapitasi/show.html. Exception raised was MissingPropertyException : No such property: id for class: play.db.jpa.GenericModel$JPAQuery.
play.exceptions.TemplateExecutionException: No such property: id for class: play.db.jpa.GenericModel$JPAQuery
at play.templates.BaseTemplate.throwException(BaseTemplate.java:84)
at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:252)
at play.templates.Template.render(Template.java:26)
at play.templates.GroovyTemplate.render(GroovyTemplate.java:184)
at play.mvc.results.RenderTemplate.<init>(RenderTemplate.java:24)
at play.mvc.Controller.renderTemplate(Controller.java:659)
at play.mvc.Controller.renderTemplate(Controller.java:639)
at play.mvc.Controller.render(Controller.java:694)
at controllers.Kapitasi.show(Kapitasi.java:62)
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:543)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:499)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:475)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:470)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:158)
at Invocation.HTTP Request(Play!)
Caused by: groovy.lang.MissingPropertyException: No such property: id for class: play.db.jpa.GenericModel$JPAQuery
at /app/views/Kapitasi/show.html.(line:5)
at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:229)
... 13 more
The exception is complaining about your DatkapjmlpstPK
class missing @Id.
Your DatkapjmlpstPK
class is an EmbeddedId class, so it does not need to extend GenericModel
精彩评论