Skip to main content

Posts

Showing posts with the label jpa

JPA Composite Key

Spinning around for about half an hour, why query with JPA stumble EJB Exception merely. Whereas what I want to do is simple enough to take distinct date data. Apparently the hands and eyes do not go together: D I have a table that consists of 2 primary keys and some additional columns, call it a content table with the following structure: Column Data Type Primary trsdate date Yes custnum int Yes custname varchar No amount double No As you can see, those trsdate and custnum column are primary key. Next, i create following entity classes based on those above table.  @Embeddable public class ContentPK implements Serializable { @Basic(optional = false) @NotNull @Column(name = "trsdate") @Temporal(TemporalType.DATE) private Date trsdate; @Basic(optional = false) @NotNull @Column(name = "custnum") private int custnum; public ContentPK() { } public ContentPK(Date trsdate, int custnum) {