How to make hibernate.hbm2ddl.auto=create-drop work?
I have specified hibernate.hbm2ddl.auto=create-drop in my XML. I'm using the H2 database.
I was hoping it would create my table for me. However, I see this on my console when I run a simple test to insert a row in a database.
What am I doing wrong?
Thanks,
Siegfried
Code:
Hibernate:
insert
into
EmployeeImpl
(employeeID, extension, firstName, homePhone, lastName)
values
(null, ?, ?, ?, ?)
0 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 42102, SQLState: 42S02
0 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Table EMPLOYEEIMPL not found; SQL statement:
insert into EmployeeImpl (employeeID, extension, firstName, homePhone, lastName) values (null, ?, ?, ?, ?) [42102-117]
Code:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="annotatedClasses">
<list>
<value>com.SIGNITEK.demo.entities.EmployeeImpl</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
<!-- JDBC connection pool (use the built-in) -->
<prop key="hibernate.connection.pool_size">1</prop>
<!-- SQL dialect -->
<!--prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop-->
<prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
<!-- Disable the second-level cache -->
<prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
<!-- Enable these to dump all executed SQL to stdout -->
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<!-- Automatically create and drop the schema in our memory db -->
<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
<!-- Disable batching as HSQL masks errors with this enabled -->
<prop key="hibernate.jdbc.batch_size">0</prop>
</props>
</property>
</bean>
Code:
package com.SIGNITEK.demo.entities;
import java.lang.reflect.*;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
@Entity()
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
public class EmployeeImpl implements Serializable, IEmployee{
/**
*
*/
public EmployeeImpl(){}
private static final long serialVersionUID = 7381724607300234811L;
@Id @GeneratedValue(strategy=GenerationType.AUTO)
private Integer employeeID;
public Integer getEmployeeID() { return employeeID; }
public void setEmployeeID(Integer id) { this.employeeID = id; }
@Basic
@Column(length=32)
private String firstName;
@Basic
@Column(length=32)
private String lastName;
@Basic
@Column(length=32)
private String homePhone;
@Basic
@Column(length=32)
private String extension;
public String getFirstName() { return firstName; }
public void setFirstName(String firstName) { this.firstName = firstName; }
public String getLastName() { return lastName; }
public void setLastName(String lastName) { this.lastName = lastName; }
public String getHomePhone() { return homePhone; }
public void setHomePhone(String homePhone) { this.homePhone = homePhone; }
public String getExtension() { return extension; }
public void setExtension(String extension) { this.extension = extension; }
}