I have the following SQL definition for a table which i can't change
CREATE TABLE network_model_property (
id NUMBER NOT NULL PRIMARY KEY,
name VARCHAR2(100) NOT NULL,
....
max NUMBER(10),
min NUMBER(10),
....
)
The JPA'ed class definition is as following
@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;
}
I'm running a simple test case which throws this exception when 'hibernate.hbm2ddl.auto=validate' is set
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
And i've tried
@Column(name = "max", columnDefinition="Decimal(10,2) default '100.00'")
and
@Column(name = "max",precision=10, scale=2)
In your table definition, the max and min columns have a precision specified, but no scale. Try using scale = 0 on your Column JPA definition for the max & min properties.
It has been a very long time, but for the sake of completeness, the easiest fix, it to change your JPA Entity to defined min and max as java.math.BigDecimal. The java.math.BigInteger and java.math.BigDecimal types provide direct conversion of SQL Numeric and Number data types.
Otherwise, to map the values correctly, you need to refer to the DB Driver for JDBC native type translation to determine what the jdbc types are translated to in java.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With