Skip to content

Instantly share code, notes, and snippets.

@jsgao0
Last active August 10, 2016 06:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsgao0/46eb98b63c6b9c7d6ff5aea696b95bbb to your computer and use it in GitHub Desktop.
Save jsgao0/46eb98b63c6b9c7d6ff5aea696b95bbb to your computer and use it in GitHub Desktop.
JPA Entity for DEMO.
package com.sample.entity;
import java.math.BigDecimal;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Lob;
import javax.persistence.Table;
@Entity
@Table(name = "Sample")
@IdClass(SampleCPK.class)
public class Sample {
@Id
@Column(nullable=false)
private String id;
@Id
@Column(nullable=false)
private BigDecimal sNo;
@Column
private String attachName;
@Column
private String attachType;
@Lob
@Column
private byte[] attachFile;
/*
* This constructor is only for JPA.
* */
Sample() {
}
/*
Getters & Setters...
*/
}
package com.sample.entity;
import java.io.Serializable;
import java.math.BigDecimal;
public class SampleCPK implements Serializable {
private String id;
private BigDecimal sNo;
public SampleCPK(){}
public String getId() {
return id;
}
public BigDecimal getSNo() {
return sNo;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + sNo.intValue();
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
SampleCPK other = (SampleCPK) obj;
if (id == null) {
if (other.id != null)
return false;
if (sNo != other.sNo)
return false;
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment