Hi.. this is my first post in this forum, so please let me know about missing info I should have provide...
My priplen is that I have a bean where I store the info of a user of my system. Using the aplication I can fill in the properties of this bean save it in the database without problems. Thoug when running that part of the program from a JUNIT test case Hibernate raises an
Code:
org.hibernate.PropertyValueException: not-null property references a null or transient value
exception. This exception is thrown by the hs.flush() method, not by the hs.save() one....
It is shaking that everything goes fine outside the JUNIT test case... Is there any implication of running an Hibernate app within Junit?? I have tested hibernate querys and I haven't have any problems....
So I provide all the data i consider necesary.... I hope someone can help
Hibernate version: 3.0.5
Mapping documents:Code:
<hibernate-mapping package="mx.com.dtc.ayde.model">
<class name="Usuario" table="USUARIO">
<id name="id" column="ID" type="java.lang.Long">
<generator class="sequence">
<param name="sequence">sec_usuario</param>
</generator>
</id>
<property name="nombre" column="NOMBRE" type="java.lang.String" not-null="true" />
<property name="apellidoPaterno" column="APELLIDO_PATERNO" type="java.lang.String" not-null="true" />
<property name="apellidoMaterno" column="APELLIDO_MATERNO" type="java.lang.String" />
<property name="mail" column="MAIL" type="java.lang.String" not-null="true" />
<property name="pasaporte" column="PASAPORTE" type="java.lang.String" not-null="true" />
<property name="contrasena" column="CONTRASENA" type="java.lang.String" not-null="true" />
<property name="estado" column="ESTADO" type="java.lang.String" not-null="true" />
<bag name="instanciasOtorgadas" table="USUARIO_INSTANCIA" lazy="false">
<key column="USUARIO_ID" />
<composite-element class="Instancia">
<property name="lectura" />
<many-to-one name="instancia" column="INSTANCIA_ID"
class="Instancia" />
</composite-element>
</bag>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
private boolean execute(Usuario usuario)
{
//....
//...
// Save the user
try
{
Session hs = HibernateSessionFactory.currentSession();
Transaction tx = hs.beginTransaction();
hs.save(usuario);
log.debug(usuario.getNombre());
hs.flush();
tx.commit();
HibernateSessionFactory.closeSession();
if(log.isDebugEnabled())
log.debug("Usuario " + usuario.getPasaporte() + " creado");
}
}
And the JUnit test case is this:
Code:
public void testExecuteConTodoOK()
{
System.out.println("\n********* Prueba con todo ok.... *********");
CrearUsuario crear = new CrearUsuario();
usuario.setApellidoPaterno("Simpson");
usuario.setContrasena(encPwd.toString());
usuario.setMail("homero.simpson@fox.com");
usuario.setPasaporte("HOMERO");
usuario.setNombre("Homero");
usuario.setApellidoMaterno("Jay");
usuario.setEstado("a");
assertEquals(true, crear.execute(usuario));
}
Full stack trace of any exception that occurs:org.hibernate.PropertyValueException: not-null property references a null or transient value: mx.com.dtc.ayde.model.Usuario.nombre
at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:164)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:190)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:70)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at mx.com.dtc.ayde.logic.CrearUsuario.execute(CrearUsuario.java:89)
at mx.com.dtc.ayde.test.PruebaDeCrearUsuario.testExecuteConTodoOK(PruebaDeCrearUsuario.java:159)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:436)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:311)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Name and version of the database you are using:Oracle 10g --> 10.1.0.4.0
The generated SQL (show_sql=true):13:06:43,952 DEBUG SQL:324 - select sec_usuario.nextval from dual
[/code]