-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Problems with Hibernate + Postgres [Solved]
PostPosted: Mon Jun 11, 2007 8:10 am 
Newbie

Joined: Mon Jun 11, 2007 7:32 am
Posts: 2
Hibernate version: hibernate-annotations-3.3.0.GA

Hi!

I'm having some problems with my Postgres DB and don't know what to do.

I have one Class Pessoa and a class PessoaFisica that extends Pessoa.
I have in the db schema a table for each class and the PessoaFisica have an association with another class Nacionalidade where one pessoafisica have a nacionalidade.
The PK for PessoaFisica is a fk for the Pessoa.

But, when i'm trying to save a pessoafisica in DB using the HibernateTemplate from HibernateDaoSuport my schema is changed and the foreing keys are modified.

This is the problem:
ERROR: insert or update on table "fisicas" violates foreign key constraint "fkcd6e3edc528e21b1"
Detalhe: Key (codigo_junta_comercial,codigo_sequencial,codigo_pessoa)=(24,000,13) is not present in table "pessoas".

I think the hibernate is changing my db schema when I make getHibernateTemplate.save(aPessoaFisica);

This fk: "fkcd6e3edc528e21b1" appears and I did not create it...

Follow the full stack trace:
Full stack trace:
Code:
org.springframework.dao.DataIntegrityViolationException: could not insert: [freedom.jucern.domain.PessoaFisica]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert: [freedom.jucern.domain.PessoaFisica]
Caused by: org.hibernate.exception.ConstraintViolationException: could not insert: [freedom.jucern.domain.PessoaFisica]
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2267)
   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660)
   at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
   at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:390)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:373)
   at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:633)
   at freedom.jucern.dao.PessoaFisicaDAO.insert(PessoaFisicaDAO.java:30)
   at freedom.jucern.service.PessoaFisicaManagerImpl.insert(PessoaFisicaManagerImpl.java:26)
   at freedom.jucern.tests.services.PessoaFisicaManagerTest.testFindByDocument(PessoaFisicaManagerTest.java:47)
   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.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.postgresql.util.PSQLException: ERROR: insert or update on table "fisicas" violates foreign key constraint "fkcd6e3edc528e21b1"
  Detalhe: Key (codigo_junta_comercial,codigo_sequencial,codigo_pessoa)=(24,000,13) is not present in table "pessoas".
   at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1548)
   at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1316)
   at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:191)
   at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:452)
   at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:351)
   at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:305)
   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2250)
   ... 32 more



The generated SQL:
Hibernate: insert into pessoas (numero_documento, nome_pessoa, codigo_junta_comercial, codigo_sequencial, codigo_pessoa) values (?, ?, ?, ?, ?)
Hibernate: insert into fisicas (codigo_nacionalidade, codigo_junta_comercial, codigo_sequencial, codigo_pessoa) values (?, ?, ?, ?)

Please help me!


Top
 Profile  
 
 Post subject: servlet configuration change
PostPosted: Mon Jun 11, 2007 9:49 am 
Newbie

Joined: Mon Jun 11, 2007 7:32 am
Posts: 2
The properties for create/update tables was removed.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.