我对无法更改的表有以下 SQL 定义
CREATE TABLE network_model_property (
id NUMBER NOT NULL PRIMARY KEY,
name VARCHAR2(100) NOT NULL,
....
max NUMBER(10),
min NUMBER(10),
....
)
JPA 的类定义如下
@Entity
@Table(name = "network_model_property")
@SequenceGenerator(name = "PropertySeq", sequenceName = "MODEL_PROPERTY_SEQUENCE")
public class ModelProperty implements Serializable {
static final long serialVersionUID = -3276944825572313129L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "PropertySeq")
@Column(name = "id")
private Long id;
@Column(name = "max")
private Double max;
@Column(name = "min")
private Double min;
public Double getMax() {
return max;
}
public void setMax(Double max) {
this.max = max;
}
public Double getMin() {
return min;
}
public void setMin(Double min) {
this.min = min;
}
我正在运行一个简单的测试用例,它在设置“hibernate.hbm2ddl.auto=validate”时抛出此异常
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: assure] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:132)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:224)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:291)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1368)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1334)
... 33 more
Caused by: org.hibernate.HibernateException: Wrong column type in POCOWN1.NETWORK_MODEL_PROPERTY for column max. Found: number, expected: double precision
at org.hibernate.mapping.Table.validateColumns(Table.java:284)
at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1116)
at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:139)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:349)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
... 38 more
我试过了
@Column(name = "max", columnDefinition="Decimal(10,2) default '100.00'")
和
@Column(name = "max",precision=10, scale=2)