Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 2.1.7
Mapping documents:
<many-to-one
name="empresa"
class="com.rhnet.entidade.empresa.Empresa"
cascade="save-update"
outer-join="auto"
update="true"
insert="true"
access="property"
column="ID_EMPRESA"
/>
Full stack trace of any exception that occurs:
com.rhnet.exception.PersistenceException:
at com.rhnet.persistencia.dao.HibernateDAO.insert(HibernateDAO.java:89)
at com.rhnet.persistencia.vaga.test.VagaDAOTest.testInsert(VagaDAOTest.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
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:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
Caused by: net.sf.hibernate.exception.GenericJDBCException: could not insert: [com.rhnet.entidade.empresa.Empresa]
at net.sf.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:90)
at net.sf.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:79)
at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:30)
at net.sf.hibernate.persister.AbstractEntityPersister.convert(AbstractEntityPersister.java:1332)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:542)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:428)
at net.sf.hibernate.impl.ScheduledIdentityInsertion.execute(ScheduledIdentityInsertion.java:29)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:941)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:866)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:784)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:747)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1397)
at net.sf.hibernate.engine.Cascades$4.cascade(Cascades.java:114)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:436)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:503)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:899)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:866)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:784)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:747)
at com.rhnet.persistencia.dao.HibernateDAO.insert(HibernateDAO.java:85)
... 16 more
Caused by: java.sql.SQLException: null, message from server: "Column 'ID_ENDERECO' cannot be null"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1905)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1109)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1203)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2090)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1680)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1527)
at com.mchange.v2.sql.filter.FilterPreparedStatement.executeUpdate(FilterPreparedStatement.java:71)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:520)
... 31 more
Name and version of the database you are using: mysql 4.1.18
Hi there! I have a class called Vaga , this class has a many to one mapping to Empresa class which has a many-to-one mapping to an Endereco class...
My test has the following code:
Code:
vaga = new Vaga();
Empresa empresa = new Empresa();
empresa.setId(new Long(1));
vaga.setEmpresa(empresa);
Cargo cargo = new Cargo();
cargo.setId(new Long(1));
vaga.setCargo(cargo);
vaga.setDataInicio(new Date());
vaga.setDataTermino(new Date());
vaga.setDescricao("asdasdasdasd");
vaga.setSalario(new MonetaryAmount(new BigDecimal(2800)));
Well, I expected Hibernate to attach the object empresa with id = 1 to the
vaga object (since I have a record with id = 1) but instead, hibernate is trying to insert a new Empresa object and as it has no other properties I
cannot insert null in one of the columns
whats wrong???
thanks