1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| Ressource res = new Ressource();
res.setMatricule("?");
res.setNom("?");
res.setPrenom("?");
res.setMotDePasse("?");
res.setLeniveau(?);
session.save(res);[/I]
(Les ? sont des données mais confidentielles ... )
Le souci c'est que lorsque je fais le "save" en base, dans la table ressource, il attend l'identifiant et dans mon code, je lui passe un objet Niveau mais, je ne sais pas comment faire !!!!
L'erreur renvoyée est :
[I]Hibernate: insert into planning.ressource (Matricule, NomR, PrenomR, MDPR, ID_RES) values (?, ?, ?, ?, ?)
15:44:10,977 WARN JDBCExceptionReporter:71 - SQL Error: 1452, SQLState: 23000
15:44:10,977 ERROR JDBCExceptionReporter:72 - Cannot add or update a child row: a foreign key constraint fails (`planning/ressource`, CONSTRAINT `FK_Ressource_Niveau` FOREIGN KEY (`ID_NIVEAU`) REFERENCES `niveau` (`CodeNiv`))
15:44:10,993 ERROR AbstractFlushingEventListener:300 - Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.simecom.planning.test.Test.main(Test.java:70)
Caused by: java.sql.BatchUpdateException: Cannot add or update a child row: a foreign key constraint fails (`planning/ressource`, CONSTRAINT `FK_Ressource_Niveau` FOREIGN KEY (`ID_NIVEAU`) REFERENCES `niveau` (`CodeNiv`))
at com.mysql.jdbc.ServerPreparedStatement.executeBatch(ServerPreparedStatement.java:665)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
... 8 more |
Partager