opa! Pessoal,
fiz uma aplicacao pequena para testar apenas um recurso com o hibernate + java, porem estou tendo prolema no foreign, alguem sabe dizer o que fiz de errado, abaixo a mensagem de erro:
SEVERE: Cannot add or update a child row: a foreign key constraint fails (`beginhibernate/advert`, CONSTRAINT `FK_advert_user` FOREIGN KEY (`aduser`) REFERENCES `advert` (`aduser`) ON DELETE CASCADE ON UPDATE CASCADE)
org.hibernate.exception.ConstraintViolationException: could not insert: [br.com.bean.Advert]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:40)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2108)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2588)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:290)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:180)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:108)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
at br.com.dao.AdvertDAO.create(AdvertDAO.java:13)
at br.com.teste.PostAdvert.main(PostAdvert.java:32)
aqui minhas tables com o foreign key:
CREATE TABLE `link_category_advert` (
`category` int(10) unsigned NOT NULL default '1',
`advert` int(10) unsigned NOT NULL default '1',
PRIMARY KEY (`category`,`advert`),
KEY `category` (`category`),
KEY `advert` (`advert`),
CONSTRAINT `FK_link_advert_category` FOREIGN KEY (`category`) REFERENCES `link_category_advert` (`category`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `FK_link_category_advert` FOREIGN KEY (`advert`) REFERENCES `link_category_advert` (`advert`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1
CREATE TABLE `advert` (
`id` int(10) unsigned NOT NULL auto_increment,
`message` varchar(45) default NULL,
`title` varchar(45) default NULL,
`aduser` int(10) unsigned NOT NULL default '1',
PRIMARY KEY (`id`),
KEY `aduser` (`aduser`),
CONSTRAINT `FK_advert_user` FOREIGN KEY (`aduser`) REFERENCES `advert` (`aduser`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1
alguma dica?