Bonjour,

Je suis en train de me mettre à JPA/Hibernate et j'ai modifié une partie de mon application pour qu'elle utilise JPA. Mais je n'arrive pas à persister une entité. Voici ce que me sort le log :

13:42:52,401 DEBUG SessionImpl:220 - opened session at timestamp: 12105925724
13:42:52,403 DEBUG JDBCTransaction:54 - begin
13:42:52,403 DEBUG ConnectionManager:415 - opening JDBC connection
13:42:52,403 TRACE DriverManagerConnectionProvider:93 - total checked-out connections: 0
13:42:52,403 TRACE DriverManagerConnectionProvider:99 - using pooled JDBC connection, pool size: 0
13:42:52,406 DEBUG JDBCTransaction:59 - current autocommit status: false
13:42:52,406 TRACE JDBCContext:210 - after transaction begin
13:42:52,409 TRACE VersionValue:44 - version unsaved-value strategy UNDEFINED
13:42:52,409 TRACE IdentifierValue:104 - id unsaved-value: 0
13:42:52,409 TRACE AbstractSaveEventListener:489 - transient instance of: org.jtheque.model.od.FilmToBuyImpl
13:42:52,409 TRACE DefaultPersistEventListener:124 - saving transient instance
13:42:52,412 TRACE AbstractSaveEventListener:152 - saving [org.jtheque.model.od.FilmToBuyImpl#<null>]
Exception occurred during event dispatching:
java.lang.NullPointerException
at org.hibernate.ejb.event.EJB3PersistEventListener.invokeSaveLifecycle(EJB3PersistEventListener.java:31)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:176)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:108)
at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:618)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:592)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:596)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:212)
at org.jtheque.core.persistance.JPAPersistanceContext.saveOrUpdate(JPAPersistanceContext.java:115)
at org.jtheque.model.dao.impl.DaoFilmsToBuy.create(DaoFilmsToBuy.java:69)
at org.jtheque.controllers.impl.ToBuyController.newFilmToBuy(ToBuyController.java:56)
at org.jtheque.view.impl.controllers.actions.tobuy.AcAddFilmToBuy.actionPerformed(AcAddFilmToBuy.java:51)
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.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.Dialog$1.run(Unknown Source)
at java.awt.Dialog$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Dialog.show(Unknown Source)
at java.awt.Component.show(Unknown Source)
at java.awt.Component.setVisible(Unknown Source)
at java.awt.Window.setVisible(Unknown Source)
at java.awt.Dialog.setVisible(Unknown Source)
at org.jtheque.view.impl.components.frames.SecondaryFrame.display(SecondaryFrame.java:61)
at org.jtheque.controllers.impl.AbstractController.displayView(AbstractController.java:100)
at org.jtheque.view.impl.controllers.actions.tobuy.AcOpenFilmsToBuyView.actionPerformed(AcOpenFilmsToBuyView.java:33)
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.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.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.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(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)
et voici le code incriminé :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public void saveOrUpdate(Data d) {
		EntityManager em = getEntityManager();
 
		EntityTransaction tr = em.getTransaction();
 
		tr.begin();
 
		if(d.isSaved()){
			em.merge(d);
		} else {
			em.persist(d);
		}
 
		tr.commit();
 
		em.close();
	}
Et voici comment je l'appelle :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
FilmToBuyImpl film = new FilmToBuyImpl();
 
film.setTitle(title);
film.setDate(IntDate.today());
 
daoFilmsToBuy.create(film);
Et voici mon entité :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
 
@Entity
@Table(name="TEST_FILM_TO_BUY")
public class FilmToBuyImpl extends FilmToBuy {
	....
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
36
37
38
39
40
41
42
43
44
45
46
47
48
 
@MappedSuperclass
public abstract class FilmToBuy extends Data{
	/* Paramètres du film */
	private String title;
	private IntDate date;
 
	/**
         * Return the title. 
         * 
         * @return the title
         */
	@Column(name = "TITLE", length = 100, unique = true, nullable = false)
	public String getTitle() {
		return title;
	}
 
	/**
         * Set a new title to the film. 
         * 
         * @param title the title to set
         */
	public void setTitle(String title) {
		this.title = title;
	}
 
	/**
         * Return the date of the film. 
         * 
         * @return the date
         */
	@org.hibernate.annotations.Type(
		type = "org.jtheque.core.persistance.IntDateUserType"
	)
	@Column(name = "DATE", nullable = false)
	public IntDate getDate() {
		return date;
	}
 
	/**
         * Set the date of the add of the film. 
         * 
         * @param date the date to set
         */
	public void setDate(IntDate date) {
		this.date = date;
	}
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
 
@MappedSuperclass
public abstract class Data implements Element{
	private int id;
	private int version;
 
	...
 
	/**
         * Return the id of this Data. 
         * 
         * @return The id
         */
	@Id
	@Column(name = "ID", nullable = false)
	@GeneratedValue(strategy = GenerationType.AUTO)
	public final int getId(){
		return id;
	}
 
	/**
         * Set the id of this Data. 
         * 
         * @param id The new id to set
         */
	public void setId(int id){
		this.id = id;
	}
 
	/**
         * Return the version of the data. The version is used to use the optimist locking of hibernate. 
         * 
         * @return The version of the data. 
         */
	@Column(name = "VERSION", nullable = false)
	@Version
	public int getVersion() {
		return version;
	}
 
	/**
         * Set the version of the data. 
         * 
         * @param version The version of the data. 
         */
	protected void setVersion(int version) {
		this.version = version;
	}
 
	...
 
	/**
         * Cette méthode permet de savoir si l'objet est enregistrée dans la base de données. 
         * 
         * @return true si l'objet est sauvegardé, sinon false
         */
	@Transient
	public boolean isSaved(){
		return getId() != 0;
	}
 
	...
}
Quelqu'un a-t-il une idée d'ou ça pourrait venir ?

Merci d'avance