私は休止状態と春とサーブレットを実験してきました。今、私は立ち往生しています。なぜこの例外が発生するのですか?hbm2ddl.autoがcreateに設定されている場合、テーブルは自動的に作成されると思いました。
appicationContext.xml
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver" />
<property name="url" value="jdbc:derby://localhost:1527/db;create=true" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="org.springpractice.domain" />
<property name="hibernateProperties">
<props>
<prop key="dialect">
org.hibernate.dialect.DerbyTenSevenDialect</prop>
<prop key="show_sql">true</prop>
<prop key="cache.provider_class">
org.hibernate.cache.NoCacheProvider</prop>
<prop key="hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
UserDetails.java
package org.springpractice.domain;
@Entity
public class UserDetails {
@Id @GeneratedValue
protected int id;
protected String name;
protected String email;
// setters/getters ...
}
Main.java
@WebServlet("/")
public class Main extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter pw = response.getWriter();
pw.println("hello from servlet");
UserDetails user = new UserDetails();
user.setEmail("bob.smith@gmail.com");
user.setName("Bob Smith");
ApplicationContext beanFactory =
WebApplicationContextUtils
.getRequiredWebApplicationContext(getServletContext());
SessionFactory sessionFactory = (SessionFactory) beanFactory.getBean("sessionFactory");
Session session = sessionFactory.openSession();
session.save(user);
session.close();
}
}
例外
org.hibernate.exception.SQLGrammarException: Table/View 'USERDETAILS' does not exist.
org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:82)
org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.continueInvocation(ConnectionProxyHandler.java:146)
org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
$Proxy10.prepareStatement(Unknown Source)
...