Hello, i've some problems with hibernate-core migration.
I'm using Spring 3.1.1.RELEASE, Hibernate-core 4.1.0 and Hsqldb 2.2.8
My SessionFactory building :
Code:
final Properties props = new Properties();
props.put("hibernate.connection.shutdown", "true");
props.put("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver");
props.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
props.put("hibernate.hbm2ddl.auto", "create-drop");
props.put("hibernate.current_session_context_class",
"org.springframework.orm.hibernate4.SpringSessionContext");
props.put("hibernate.show_sql", "true");
final DatasourceConnectionProviderImpl service = new DatasourceConnectionProviderImpl();
service.setDataSource(new SingleConnectionDataSource("jdbc:hsqldb:mem:test", "sa", "", true));
service.configure(props);
final ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().addService(
ConnectionProvider.class, service).applySettings(props).buildServiceRegistry();
final MetadataSources metadataSources = new MetadataSources(serviceRegistry);
metadataSources.addResource("myPackage/ObjectToTest.hbm.xml");
final Metadata metadata = metadataSources.buildMetadata();
sessionFactory = metadata.buildSessionFactory();
My test :
Code:
@org.junit.Test
public void testPersist() {
new TransactionTemplate(new HibernateTransactionManager(sessionFactory)).execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(final TransactionStatus status) {
final Session currentSession = sessionFactory.getCurrentSession();
final ObjectToTest object = new ObjectToTest("myText");
currentSession.persist(object);
}
});
}
My mapping :
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="false"
xmlns="http://www.hibernate.org/xsd/hibernate-mapping"
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-mapping hibernate-mapping-4.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<class name="myPackage.ObjectToTest">
<id name="id">
<generator class="native" />
</id>
<property name="text" />
</class>
</hibernate-mapping>
With this configuration i have :
Code:
Caused by: java.sql.SQLIntegrityConstraintViolationException: integrity constraint violation: NOT NULL check constraint; SYS_CT_10025 table: "ObjectToTest" column: "id"
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.executeUpdate(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
I saw that native is deprecated but i don't know how to replace it
Any ideas ?
Thanks