Salut,
Dans mon projet Java, j'utilise Hibernate.
Je dois entrer dans une de mes tables un clé primaire qui est de type String.
Première question:
Est ce que je peux utiliser le generator class = 'assigned' pour entrer un String comme clé primaire?
Si oui, j'ai un problème lorsque je veux sauver les nouvelles donées dans la base de données.
Voici les exceptions que je reçois
Voici mon code :Citation:
net.sf.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): com.minosis.hibernate.Virement
at net.sf.hibernate.id.Assigned.generate(Assigned.java:26)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:765)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:738)
at org.sambreville.pos.tools.Request.add_virement(Request.java:645)
at org.sambreville.pos.tools.Money.actionPerformed(Money.java:126)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Je vous demande de l'aide car je ne vois pas trop où est l'erreur.Citation:
Virement virement = new Virement();
Transaction tx=null;
try {
tx = (Transaction) session.beginTransaction();
} catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
virement.setIdVente(numTic);
virement.setCommunication(num_commu);
virement.setCompte("eeee");
try {
session.save(virement);
} catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
tx.commit();
} catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Merci d'avance