虽然我在ejb项目中包含了持久性单元,但我无法创建数据库。有没有人知道这里发生了什么? 我在这里包含了我的代码 汽车类:
@Entity
@Table(name = "CARS")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = Cars.findAllCar, query = "SELECT c FROM Cars c"),
@NamedQuery(name = "Cars.findByVinNo", query = "SELECT c FROM Cars c WHERE c.vinNo = :vinNo"),
@NamedQuery(name = "Cars.findByModelNo", query = "SELECT c FROM Cars c WHERE c.modelNo = :modelNo"),
@NamedQuery(name = "Cars.findByModelName", query = "SELECT c FROM Cars c WHERE c.modelName = :modelName"),
@NamedQuery(name = "Cars.findByManufacturer", query = "SELECT c FROM Cars c WHERE c.manufacturer = :manufacturer"),
@NamedQuery(name = "Cars.findByCarType", query = "SELECT c FROM Cars c WHERE c.carType = :carType"),
@NamedQuery(name = "Cars.findByCarDescrip", query = "SELECT c FROM Cars c WHERE c.carDescrip = :carDescrip"),
@NamedQuery(name = "Cars.findByCarUrl", query = "SELECT c FROM Cars c WHERE c.carUrl = :carUrl")})
public class Cars implements Serializable {
public static final String findAllCar = "Cars.getAll";
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 50)
@Column(name = "VIN_NO")
private String vinNo;
@Size(max = 50)
@Column(name = "MODEL_NO")
private String modelNo;
@Size(max = 50)
@Column(name = "MODEL_NAME")
private String modelName;
@Size(max = 100)
@Column(name = "MANUFACTURER")
private String manufacturer;
@Size(max = 20)
@Column(name = "CAR_TYPE")
private String carType;
@Lob
@Column(name = "CAR_THUMBNAIL")
private Serializable carThumbnail;
@Size(max = 100)
@Column(name = "CAR_DESCRIP")
private String carDescrip;
@Size(max = 100)
@Column(name = "CAR_URL")
private String carUrl;
public Cars() {
}
public Cars(String vinNo) {
this.vinNo = vinNo;
}
public String getVinNo() {
return vinNo;
}
public void setVinNo(String vinNo) {
this.vinNo = vinNo;
}
public String getModelNo() {
return modelNo;
}
public void setModelNo(String modelNo) {
this.modelNo = modelNo;
}
public String getModelName() {
return modelName;
}
public void setModelName(String modelName) {
this.modelName = modelName;
}
public String getManufacturer() {
return manufacturer;
}
public void setManufacturer(String manufacturer) {
this.manufacturer = manufacturer;
}
public String getCarType() {
return carType;
}
public void setCarType(String carType) {
this.carType = carType;
}
public Serializable getCarThumbnail() {
return carThumbnail;
}
public void setCarThumbnail(Serializable carThumbnail) {
this.carThumbnail = carThumbnail;
}
public String getCarDescrip() {
return carDescrip;
}
public void setCarDescrip(String carDescrip) {
this.carDescrip = carDescrip;
}
public String getCarUrl() {
return carUrl;
}
public void setCarUrl(String carUrl) {
this.carUrl = carUrl;
}
@Override
public int hashCode() {
int hash = 0;
hash += (vinNo != null ? vinNo.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Cars)) {
return false;
}
Cars other = (Cars) object;
if ((this.vinNo == null && other.vinNo != null) || (this.vinNo != null && !this.vinNo.equals(other.vinNo))) {
return false;
}
return true;
}
@Override
public String toString() {
return "fit5042.entities.Cars[ vinNo=" + vinNo + " ]";
}
}
客户类:
@Entity
@Table(name = "CUSTOMER")
@NamedQueries({@NamedQuery(name = Customer.GET_ALL_QUERY_NAME, query = "SELECT c FROM Customer c")})
public class Customer implements Serializable{
public static final String GET_ALL_QUERY_NAME = "Customer.getAll";
private int id;
private String surname;
private String name;
private String email;
private String password;
private String type;
private String address;
private String tel;
private Set<Orders> order;
//private Set<Cars> car;
public Customer() {
}
public Customer(int id,String surname, String name, String email,
String password, String type, String address, String tel, Orders orders) {
super();
this.id = id;
this.surname = surname;
this.name = name;
this.email = email;
this.password = password;
this.type = type;
this.address = address;
this.tel = tel;
this.order = new HashSet<>();
//this.car = new HashSet<>();
}
@Id
@GeneratedValue
@Column(name = "customer_id")
public int getId(){
return id;
}
public void setId(int id)
{
this.id = id;
}
@Column(name = "customer_surName")
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
@Column(name = "customer_name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Column(name = "customer_email")
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Column(name = "customer_passwd")
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Column(name = "type")
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@Column(name = "customer_address")
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@Column(name = "customer_tel")
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
/*@OneToMany(mappedBy = "customer")
public Set<Cars> getCar() {
return car;
}
public void setCar(Set<Cars> car) {
this.car = car;
}*/
@OneToMany(mappedBy = "customer")
public Set<Orders> getOrder() {
return order;
}
public void setOrder(Set<Orders> order) {
this.order = order;
}
}
销售员课程
@Entity
@Table(name = "SALESPERSON")
public class SalesPerson {
public static final String GET_ALL_QUERY_NAME = "Customer.getAll";
private int id;
private String surname;
private String name;
private String email;
private String password;
private String type;
private String address;
private String tel;
private Set<Orders> order;
public SalesPerson() {
}
public SalesPerson(int id,String surname, String name, String email,
String password, String type, String address, String tel, Orders orders) {
this.id = id;
this.surname = surname;
this.name = name;
this.email = email;
this.password = password;
this.type = type;
this.address = address;
this.tel = tel;
this.order = new HashSet<>();
}
@Id
@GeneratedValue
@Column(name = "sales_id")
public int getId(){
return id;
}
public void setId(int id)
{
this.id = id;
}
@Column(name = "sales_surName")
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
@Column(name = "sales_name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Column(name = "sales_email")
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Column(name = "sales_passwd")
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Column(name = "type")
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@Column(name = "sales_address")
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@Column(name = "sales_tel")
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
@OneToMany( mappedBy = "salesperson")
public Set<Orders> getOrder() {
return order;
}
public void setOrder(Set<Orders> order) {
this.order = order;
}
}
订单类:
@Entity
@Table(name = "ORDERS")
public class Orders implements Serializable {
@Id
@GeneratedValue
@Column(name = "Order_id")
private int order_id;
@ManyToOne
@JoinColumn(name = "customer_id")
private Customer customer;
@ManyToOne
@JoinColumn(name = "sales_id")
private SalesPerson salesPerson;
@OneToOne(mappedBy = "orders")
private Cars car;
public Orders(int order_id, Customer customer, SalesPerson salesPerson, Cars car) {
this.order_id = order_id;
this.customer = customer;
this.salesPerson = salesPerson;
this.car = car;
}
public int getOrder_id() {
return order_id;
}
public void setOrder_id(int order_id) {
this.order_id = order_id;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public SalesPerson getSalesPerson() {
return salesPerson;
}
public void setSalesPerson(SalesPerson salesPerson) {
this.salesPerson = salesPerson;
}
public Cars getCar() {
return car;
}
public void setCar(Cars car) {
this.car = car;
}
}
四个表之间的关系应该是:客户和销售人员将与订单有一对多的关系。订单与汽车有一对一的关系。
任何帮助将不胜感激