我是h2 database.i的新手,创建了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>
My.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 persistent database.But在h2数据库中不起作用。我的方法出了什么问题? 查询是否与内存和持久数据库不同? 任何帮助将不胜感激!!