Hi All
I'm using the following environment:
Spring 3.0.5
Hibernate 3.3.6
I created this hbm:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="it.TestRuolo" table="TEST_ROLE">
<id name="roleId" type="int">
<column name="ROLE_ID" length="10"/>
<generator class="native"/>
</id>
<property name="roleDescription" not-null="false" type="string" length="50">
<column name="ROLE_DESCRIPTION" />
</property>
<property name="roleLongDescription" type="string" unique="true" not-null="true" length="255">
<column name="ROLE_LONG_DESCRIPTION" />
</property>
</class>
</hibernate-mapping>
this mapping class:
Code:
package it;
public class TestRuolo {
private int roleId;
private String roleDescription;
private String roleLongDescription;
public int getRoleId() {
return roleId;
}
public void setRoleId(int roleId) {
this.roleId = roleId;
}
public String getRoleDescription() {
return roleDescription;
}
public void setRoleDescription(String roleDescription) {
this.roleDescription = roleDescription;
}
public String getRoleLongDescription() {
return roleLongDescription;
}
public void setRoleLongDescription(String roleLongDescription) {
this.roleLongDescription = roleLongDescription;
}
}
and this test class:
Code:
package test;
import it.SimpleDao;
import it.TestRuolo;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestHib {
/**
* @param args
*/
public static void main(String[] args) {
try {
String[] springCtx = {"spring-aop-ctx.xml"};
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(springCtx);
SimpleDao sd = (SimpleDao)ctx.getBean("simpledao");
TestRuolo tr = new TestRuolo();
sd.saveTest(tr);
} catch (Exception e) {
e.printStackTrace();
}
}
}
I created this hibernate configuration file:
Code:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" p:dataSource-ref="dataSourceHibernate">
<property name="mappingResources">
<list>
<value>
role.hbm.xml
</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">
true
</prop>
<prop key="hibernate.generate_statistics">
true
</prop>
<prop key="hibernate.format_sql">
true
</prop>
<prop key="hibernate.hbm2ddl.auto">
create
</prop>
</props>
</property>
</bean>
When i execute the test i see in the log file the following:
Code:
create table TEST_ROLE (
ROLE_ID integer not null auto_increment,
ROLE_DESCRIPTION varchar(255),
ROLE_LONG_DESCRIPTION varchar(255),
primary key (ROLE_ID)
)
As you can see when it creates the table the not-null instruction is not considered and when i execute the test i can save in the database a total empty object.
Can anybody tell me where i'm wrong?
Cheers,
Angelo