我是 h2 数据库的新手。我创建了如下所示的 sessionfactory。
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.h2.Driver" />
<property name="url" value="jdbc:h2:~/selva;DB_CLOSE_DELAY=-1" />
<property name="username" value="" />
<property name="password" value="" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.selva.meetinghall.domain.My</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
</props>
</property>
</bean>
我的.java
@Entity
@Table(name="my")
@Repository
public class My implements java.io.Serializable {
private static final long serialVersionUID = -1798070786993154670L;
@Id
@Column(name ="Id")
private int id;
@Column(name ="Name")
private String name;
//getter and setter
}
道:
Session session=sessionfactory.openSession();
Transaction tx=session.beginTransaction();
My my=new My();
my.setId(1);
my.setName("selva");
session.save(my);
tx.commit();
我得到了如下错误。
Hibernate: insert into my (Name, Id) values (?, ?)
2015-01-20 18:41:02,911 WARN org.hibernate.util.JDBCExceptionReporter.logExceptions:77 - SQL Error: 42102, SQLState: 42S02
2015-01-20 18:41:02,911 ERROR org.hibernate.util.JDBCExceptionReporter.logExceptions:78 - Table "MY" not found; SQL statement:
insert into my (Name, Id) values (?, ?) [42102-185]
2015-01-20 18:41:02,913 ERROR org.hibernate.event.def.AbstractFlushingEventListener.performExecutions:301 - Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: could not insert: [com.selva.meetinghall.domain.My]
上面的代码适用于 mssql 持久数据库。但不适用于 h2 数据库。我的方法有什么问题?内存和持久数据库的查询是否不同?任何帮助将不胜感激!!