変更できないテーブルに対して次の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)