两个问题:所以我在要映射到JPA的表中有一个现有数据库。 JPA是@Immutable,因为不应允许该应用程序修改表。但是在启动时,hibernate试图为JPA创建一个表,而不是使用数据库中已有的表。
@Entity
@Table(name = "instrument")
@Immutable
public class Instrument implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "name")
private String name;
@Column(name = "ticker")
private String ticker;
@Column(name = "value")
private double value;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTicker() {
return ticker;
}
public void setTicker(String ticker) {
this.ticker = ticker;
}
No Title
public double getValue() {
return value;
}
public void setValue(double value) {
this.value = value;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((ticker == null) ? 0 : ticker.hashCode());
long temp;
temp = Double.doubleToLongBits(value);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Instrument other = (Instrument) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (ticker == null) {
if (other.ticker != null)
return false;
} else if (!ticker.equals(other.ticker))
return false;
if (Double.doubleToLongBits(value) != Double.doubleToLongBits(other.value))
return false;
return true;
}
@Override
public String toString() {
return "Instrument [id=" + id + ", name=" + name + ", ticker=" + ticker + ", value=" + value + "]";
}
}
第二个问题是如何在创建其他JPA实体之前让我的import.sql在启动时填充h2数据库,而在创建该J2实体之前,它现在是根据控制台运行的