package ch03.com.ma.entity;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
* Customer generated by MyEclipse Persistence Tools
*/
@Entity
@Table(name = "customer", catalog = "test", uniqueConstraints = {})
public class Customer implements java.io.Serializable {
// Fields
/**
*
*/
private static final long serialVersionUID = -3845142300298239748L;
private CustomerId id;
private String shortName;
private Double registeredCapital;
// Constructors
/** default constructor */
public Customer() {
}
/** minimal constructor */
public Customer(CustomerId id, Double registeredCapital) {
this.id = id;
this.registeredCapital = registeredCapital;
}
/** full constructor */
public Customer(CustomerId id, String shortName, Double registeredCapital) {
this.id = id;
this.shortName = shortName;
this.registeredCapital = registeredCapital;
}
// Property accessors
@EmbeddedId
@AttributeOverrides( {
@AttributeOverride(name = "id", column = @Column(name = "id", unique = false, nullable = false, insertable = true, updatable = true)),
@AttributeOverride(name = "name", column = @Column(name = "name", unique = false, nullable = false, insertable = true, updatable = true)) })
public CustomerId getId() {
return this.id;
}
public void setId(CustomerId id) {
this.id = id;
}
@Column(name = "shortName", unique = false, nullable = true, insertable = true, updatable = true)
public String getShortName() {
return this.shortName;
}
public void setShortName(String shortName) {
this.shortName = shortName;
}
@Column(name = "registeredCapital", unique = false, nullable = false, insertable = true, updatable = true, precision = 22, scale = 0)
public Double getRegisteredCapital() {
return this.registeredCapital;
}
public void setRegisteredCapital(Double registeredCapital) {
this.registeredCapital = registeredCapital;
}
}
package ch03.com.ma.entity;
import javax.persistence.Column;
import javax.persistence.Embeddable;
/**
* CustomerId generated by MyEclipse Persistence Tools
*/
@Embeddable
public class CustomerId implements java.io.Serializable {
// Fields
/**
*
*/
private static final long serialVersionUID = -1899332459207758826L;
private Integer id;
private String name;
// Constructors
/** default constructor */
public CustomerId() {
}
/** full constructor */
public CustomerId(Integer id, String name) {
this.id = id;
this.name = name;
}
// Property accessors
@Column(name = "id", unique = false, nullable = false, insertable = true, updatable = true)
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
@Column(name = "name", unique = false, nullable = false, insertable = true, updatable = true)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public boolean equals(Object other) {
if ((this == other))
return true;
if ((other == null))
return false;
if (!(other instanceof CustomerId))
return false;
CustomerId castOther = (CustomerId) other;
return ((this.getId() == castOther.getId()) || (this.getId() != null
&& castOther.getId() != null && this.getId().equals(
castOther.getId())))
&& ((this.getName() == castOther.getName()) || (this.getName() != null
&& castOther.getName() != null && this.getName()
.equals(castOther.getName())));
}
public int hashCode() {
int result = 17;
result = 37 * result + (getId() == null ? 0 : this.getId().hashCode());
result = 37 * result
+ (getName() == null ? 0 : this.getName().hashCode());
return result;
}
}
1、切换到DB模式,在DB Browser中NEW 一个新的数据库连接
2、加入与数据库匹配的数据库连接包后即可创建连接
3、选择要映射的表,右键,EJB3 REVERSE ENGINEERING ,选择相应的包即可