IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JPA Java Discussion :

NullPointerException lors du persist


Sujet :

JPA Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Expert confirmé
    Avatar de Baptiste Wicht
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2005
    Messages
    7 431
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Suisse

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2005
    Messages : 7 431
    Par défaut NullPointerException lors du persist
    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

  2. #2
    Expert confirmé
    Avatar de Baptiste Wicht
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2005
    Messages
    7 431
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Suisse

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2005
    Messages : 7 431
    Par défaut
    Je suis en train de me demander si ça ne pourrait pas venir mon héritage (FilmToBuyImpl hérite de FilmToBuy (MappedSuperClass) qui hérite de Data (MappedSuperClass)). Je ne sais pas si c'est possible de faire ainsi ?

    Mais si ça venait de là, est-ce qu'Hibernate ne me l'aurait pas dit au lieu de planter violemment ?

  3. #3
    Expert confirmé
    Avatar de Baptiste Wicht
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2005
    Messages
    7 431
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Suisse

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2005
    Messages : 7 431
    Par défaut
    Comme j'ai toujours pas trouvé la cause de l'erreur, j'ai complètement isolé le code posant problème et l'ai encore simplifié pour voir exactement d'ou pourrait venir l'erreur.

    En fait, avec un code minimal et une entité toute simple, ça ne marche pas non plus. Voici mon code de test :

    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
    public class JPATest extends AbstractTest{
    	public static void main(String... args){
    		LogManager logManager = LogManager.getInstance();
    		logManager.init();
     
    		Server hsqlServer = null;
    		try {
                hsqlServer =(Server) Class.forName("org.hsqldb.Server").newInstance();
     
                PrintWriter writer = new PrintWriter(new ServerLogWriter(hsqlServer.getClass()));
     
                hsqlServer.setLogWriter(writer);
                hsqlServer.setErrWriter(writer);
                hsqlServer.setDatabasePath(0, "localhost/dvd");
                hsqlServer.setDatabaseName(0, "dvd");
                hsqlServer.start();
            } catch (Exception e1) {
                e1.printStackTrace();
            }
     
    		Ejb3Configuration config = new Ejb3Configuration();
     
    		config.addAnnotatedClass(TestEntity.class);
     
    		config.setProperty("hibernate.show_sql", "true");
    		config.setProperty("hibernate.format_sql", "true");
    		config.setProperty("use_sql_comments", "false");
     
    		config.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver");
    		config.setProperty("hibernate.connection.url", "jdbc:hsqldb:hsql://localhost/dvd");
    		config.setProperty("hibernate.connection.username", "sa");
    		config.setProperty("hibernate.connection.password", "");
     
    		config.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
     
    		config.setProperty("hibernate.hbm2ddl.auto", "update");
     
    		EntityManagerFactory emf = config.buildEntityManagerFactory();
     
    		EntityManager em = emf.createEntityManager();
     
    		TestEntity entity = new TestEntity();
    		entity.setTitle("Bonjour");
     
    		try{
    			em.persist(entity);
    		} catch(NullPointerException e){
    			e.printStackTrace();
    		}
     
    		em.close();
     
    		emf.close();
     
    		hsqlServer.stop();
     
    		logManager.close();
     
    		System.exit(0);
    	}
    }
    et voici l'entité telle que je l'ai créée :

    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
    @Entity
    @Table(name="TEST")
    public class TestEntity {
    	private String title;
    	private int id;
    	private int version;
     
    	@Column(name = "TITLE", length = 100, unique = true, nullable = false)
    	public String getTitle() {
    		return title;
    	}
     
    	public void setTitle(String title) {
    		this.title = title;
    	}
     
    	@Id
    	@Column(name = "ID", nullable = false)
    	@GeneratedValue(strategy = GenerationType.AUTO)
    	public final int getId(){
    		return id;
    	}
     
    	public void setId(int id){
    		this.id = id;
    	}
     
    	@Column(name = "VERSION", nullable = false)
    	@Version
    	public int getVersion() {
    		return version;
    	}
     
    	public void setVersion(int version) {
    		this.version = version;
    	}
    }
    et voici la trace complète avec l'erreur à la fin :

    21:16:30,817 INFO Version:15 - Hibernate EntityManager 3.2.0.CR3
    21:16:30,831 INFO Version:15 - Hibernate Annotations 3.2.0.CR3
    21:16:30,837 INFO Environment:500 - Hibernate 3.2.0.cr5
    21:16:30,840 INFO Environment:533 - hibernate.properties not found
    21:16:30,841 INFO Environment:667 - Bytecode provider name : cglib
    21:16:30,844 INFO Environment:584 - using JDK 1.4 java.sql.Timestamp handling
    21:16:30,971 DEBUG NamingHelper:30 - Not Ejb3Configuration to JNDI, no JNDI name configured
    21:16:30,973 DEBUG Configuration:1209 - Preparing to build session factory with filters : {}
    21:16:30,973 DEBUG AnnotationConfiguration:235 - Execute first pass mapping processing
    21:16:31,013 DEBUG AnnotationConfiguration:435 - Process hbm files
    21:16:31,013 DEBUG AnnotationConfiguration:443 - Process annotated classes
    21:16:31,016 INFO AnnotationBinder:387 - Binding entity from annotated class: org.jtheque.tests.techno.jpa.TestEntity
    21:16:31,032 DEBUG Ejb3Column:161 - Binding column DTYPE unique false
    21:16:31,045 DEBUG EntityBinder:212 - Import with entity name=TestEntity
    21:16:31,050 INFO EntityBinder:340 - Bind entity org.jtheque.tests.techno.jpa.TestEntity on table TEST
    21:16:31,055 DEBUG AnnotationBinder:940 - Processing org.jtheque.tests.techno.jpa.TestEntity property annotation
    21:16:31,074 DEBUG AnnotationBinder:1032 - Processing annotations of org.jtheque.tests.techno.jpa.TestEntity.id
    21:16:31,076 DEBUG Ejb3Column:161 - Binding column ID unique false
    21:16:31,076 DEBUG AnnotationBinder:1153 - id is an id
    21:16:31,080 DEBUG SimpleValueBinder:220 - building SimpleValue for id
    21:16:31,083 DEBUG PropertyBinder:122 - Building property id
    21:16:31,087 DEBUG PropertyBinder:155 - Cascading id with null
    21:16:31,087 DEBUG AnnotationBinder:1186 - Bind @Id on id
    21:16:31,087 DEBUG AnnotationBinder:1032 - Processing annotations of org.jtheque.tests.techno.jpa.TestEntity.title
    21:16:31,087 DEBUG Ejb3Column:161 - Binding column TITLE unique true
    21:16:31,088 DEBUG PropertyBinder:102 - binding property title with lazy=false
    21:16:31,088 DEBUG SimpleValueBinder:220 - building SimpleValue for title
    21:16:31,088 DEBUG PropertyBinder:122 - Building property title
    21:16:31,088 DEBUG PropertyBinder:155 - Cascading title with null
    21:16:31,088 DEBUG AnnotationBinder:1032 - Processing annotations of org.jtheque.tests.techno.jpa.TestEntity.version
    21:16:31,088 DEBUG Ejb3Column:161 - Binding column VERSION unique false
    21:16:31,088 DEBUG AnnotationBinder:1203 - version is a version property
    21:16:31,088 DEBUG PropertyBinder:102 - binding property version with lazy=false
    21:16:31,089 DEBUG SimpleValueBinder:220 - building SimpleValue for version
    21:16:31,089 DEBUG PropertyBinder:122 - Building property version
    21:16:31,089 DEBUG PropertyBinder:155 - Cascading version with null
    21:16:31,089 DEBUG AnnotationBinder:1223 - Version name: version, unsavedValue: undefined
    21:16:31,091 DEBUG AnnotationConfiguration:329 - processing manytoone fk mappings
    21:16:31,094 DEBUG Configuration:1044 - processing extends queue
    21:16:31,094 DEBUG Configuration:1048 - processing collection mappings
    21:16:31,094 DEBUG Configuration:1059 - processing native query and ResultSetMapping mappings
    21:16:31,094 DEBUG Configuration:1067 - processing association property references
    21:16:31,094 DEBUG Configuration:1089 - processing foreign key constraints
    21:16:31,105 TRACE ClassValidator:160 - ResourceBundle ValidatorMessages not found in thread context classloader
    21:16:31,105 DEBUG ClassValidator:170 - ResourceBundle ValidatorMessages not found in Validator classloader. Delegate to org.hibernate.validator.resources.DefaultValidatorMessages
    21:16:31,171 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
    21:16:31,171 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 20
    21:16:31,171 INFO DriverManagerConnectionProvider:45 - autocommit mode: false
    21:16:31,173 INFO DriverManagerConnectionProvider:80 - using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:hsql://localhost/dvd
    21:16:31,174 INFO DriverManagerConnectionProvider:83 - connection properties: {user=sa, password=}
    21:16:31,174 TRACE DriverManagerConnectionProvider:93 - total checked-out connections: 0
    21:16:31,174 DEBUG DriverManagerConnectionProvider:109 - opening new JDBC connection
    21:16:31,207 DEBUG DriverManagerConnectionProvider:115 - created connection to: jdbc:hsqldb:hsql://localhost/dvd, Isolation Level: 2
    21:16:31,228 INFO SettingsFactory:81 - RDBMS: HSQL Database Engine, version: 1.8.0
    21:16:31,228 INFO SettingsFactory:82 - JDBC driver: HSQL Database Engine Driver, version: 1.8.0
    21:16:31,228 TRACE DriverManagerConnectionProvider:129 - returning connection to pool, pool size: 1
    21:16:31,246 INFO Dialect:141 - Using dialect: org.hibernate.dialect.HSQLDialect
    21:16:31,251 INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
    21:16:31,253 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
    21:16:31,253 INFO SettingsFactory:134 - Automatic flush during beforeCompletion(): disabled
    21:16:31,253 INFO SettingsFactory:138 - Automatic session close at end of transaction: disabled
    21:16:31,253 INFO SettingsFactory:145 - JDBC batch size: 15
    21:16:31,253 INFO SettingsFactory:148 - JDBC batch updates for versioned data: disabled
    21:16:31,254 INFO SettingsFactory:153 - Scrollable result sets: enabled
    21:16:31,254 DEBUG SettingsFactory:157 - Wrap result sets: disabled
    21:16:31,254 INFO SettingsFactory:161 - JDBC3 getGeneratedKeys(): disabled
    21:16:31,255 INFO SettingsFactory:169 - Connection release mode: auto
    21:16:31,255 INFO SettingsFactory:196 - Default batch fetch size: 1
    21:16:31,255 INFO SettingsFactory:200 - Generate SQL with comments: disabled
    21:16:31,255 INFO SettingsFactory:204 - Order SQL updates by primary key: disabled
    21:16:31,256 INFO SettingsFactory:369 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
    21:16:31,258 INFO ASTQueryTranslatorFactory:24 - Using ASTQueryTranslatorFactory
    21:16:31,258 INFO SettingsFactory:212 - Query language substitutions: {}
    21:16:31,258 INFO SettingsFactory:217 - JPA-QL strict compliance: disabled
    21:16:31,258 INFO SettingsFactory:222 - Second-level cache: enabled
    21:16:31,259 INFO SettingsFactory:226 - Query cache: disabled
    21:16:31,259 INFO SettingsFactory:356 - Cache provider: org.hibernate.cache.NoCacheProvider
    21:16:31,259 INFO SettingsFactory:241 - Optimize cache for minimal puts: disabled
    21:16:31,259 INFO SettingsFactory:250 - Structured second-level cache entries: disabled
    21:16:31,261 TRACE SQLExceptionConverterFactory:52 - Using dialect defined converter
    21:16:31,265 INFO SettingsFactory:270 - Echoing all SQL to stdout
    21:16:31,266 INFO SettingsFactory:277 - Statistics: disabled
    21:16:31,266 INFO SettingsFactory:281 - Deleted entity synthetic identifier rollback: disabled
    21:16:31,266 INFO SettingsFactory:296 - Default entity-mode: pojo
    21:16:31,287 TRACE ClassValidator:160 - ResourceBundle ValidatorMessages not found in thread context classloader
    21:16:31,287 DEBUG ClassValidator:170 - ResourceBundle ValidatorMessages not found in Validator classloader. Delegate to org.hibernate.validator.resources.DefaultValidatorMessages
    21:16:31,296 INFO SessionFactoryImpl:161 - building session factory
    21:16:31,297 DEBUG SessionFactoryImpl:173 - Session factory constructed with filter configurations : {}
    21:16:31,298 DEBUG SessionFactoryImpl:177 - instantiating session factory with properties: {...}
    21:16:31,495 DEBUG AbstractEntityPersister:2673 - Static SQL for entity: org.jtheque.tests.techno.jpa.TestEntity
    21:16:31,496 DEBUG AbstractEntityPersister:2678 - Version select: select VERSION from TEST where ID =?
    21:16:31,496 DEBUG AbstractEntityPersister:2681 - Snapshot select: select testentity_.ID, testentity_.TITLE as TITLE0_, testentity_.VERSION as VERSION0_ from TEST testentity_ where testentity_.ID=?
    21:16:31,496 DEBUG AbstractEntityPersister:2684 - Insert 0: insert into TEST (TITLE, VERSION, ID) values (?, ?, ?)
    21:16:31,496 DEBUG AbstractEntityPersister:2685 - Update 0: update TEST set TITLE=?, VERSION=? where ID=? and VERSION=?
    21:16:31,496 DEBUG AbstractEntityPersister:2686 - Delete 0: delete from TEST where ID=? and VERSION=?
    21:16:31,496 DEBUG AbstractEntityPersister:2690 - Identity insert: insert into TEST (ID, TITLE, VERSION) values (null, ?, ?)
    21:16:31,514 DEBUG EntityLoader:79 - Static select for entity org.jtheque.tests.techno.jpa.TestEntity: select testentity0_.ID as ID0_0_, testentity0_.TITLE as TITLE0_0_, testentity0_.VERSION as VERSION0_0_ from TEST testentity0_ where testentity0_.ID=?
    21:16:31,514 DEBUG EntityLoader:79 - Static select for entity org.jtheque.tests.techno.jpa.TestEntity: select testentity0_.ID as ID0_0_, testentity0_.TITLE as TITLE0_0_, testentity0_.VERSION as VERSION0_0_ from TEST testentity0_ where testentity0_.ID=?
    21:16:31,514 DEBUG EntityLoader:79 - Static select for entity org.jtheque.tests.techno.jpa.TestEntity: select testentity0_.ID as ID0_0_, testentity0_.TITLE as TITLE0_0_, testentity0_.VERSION as VERSION0_0_ from TEST testentity0_ where testentity0_.ID=?
    21:16:31,515 DEBUG EntityLoader:79 - Static select for entity org.jtheque.tests.techno.jpa.TestEntity: select testentity0_.ID as ID0_0_, testentity0_.TITLE as TITLE0_0_, testentity0_.VERSION as VERSION0_0_ from TEST testentity0_ where testentity0_.ID=?
    21:16:31,515 DEBUG EntityLoader:79 - Static select for entity org.jtheque.tests.techno.jpa.TestEntity: select testentity0_.ID as ID0_0_, testentity0_.TITLE as TITLE0_0_, testentity0_.VERSION as VERSION0_0_ from TEST testentity0_ where testentity0_.ID=?
    21:16:31,523 DEBUG EntityLoader:34 - Static select for action ACTION_MERGE on entity org.jtheque.tests.techno.jpa.TestEntity: select testentity0_.ID as ID0_0_, testentity0_.TITLE as TITLE0_0_, testentity0_.VERSION as VERSION0_0_ from TEST testentity0_ where testentity0_.ID=?
    21:16:31,523 DEBUG EntityLoader:34 - Static select for action ACTION_REFRESH on entity org.jtheque.tests.techno.jpa.TestEntity: select testentity0_.ID as ID0_0_, testentity0_.TITLE as TITLE0_0_, testentity0_.VERSION as VERSION0_0_ from TEST testentity0_ where testentity0_.ID=?
    21:16:31,525 DEBUG SessionFactoryObjectFactory:39 - initializing class SessionFactoryObjectFactory
    21:16:31,526 DEBUG SessionFactoryObjectFactory:76 - registered: 4028818519de90070119de9008a30000 (unnamed)
    21:16:31,527 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
    21:16:31,527 DEBUG SessionFactoryImpl:308 - instantiated session factory
    21:16:31,530 INFO SchemaUpdate:115 - Running hbm2ddl schema update
    21:16:31,530 INFO SchemaUpdate:126 - fetching database metadata
    21:16:31,530 TRACE DriverManagerConnectionProvider:93 - total checked-out connections: 0
    21:16:31,530 TRACE DriverManagerConnectionProvider:99 - using pooled JDBC connection, pool size: 0
    21:16:31,540 INFO SchemaUpdate:138 - updating schema
    21:16:31,540 DEBUG AnnotationConfiguration:235 - Execute first pass mapping processing
    21:16:31,540 DEBUG AnnotationConfiguration:435 - Process hbm files
    21:16:31,540 DEBUG AnnotationConfiguration:443 - Process annotated classes
    21:16:31,540 DEBUG AnnotationConfiguration:329 - processing manytoone fk mappings
    21:16:31,541 DEBUG Configuration:1044 - processing extends queue
    21:16:31,541 DEBUG Configuration:1048 - processing collection mappings
    21:16:31,542 DEBUG Configuration:1059 - processing native query and ResultSetMapping mappings
    21:16:31,542 DEBUG Configuration:1067 - processing association property references
    21:16:31,542 DEBUG Configuration:1089 - processing foreign key constraints
    21:16:31,542 TRACE ClassValidator:160 - ResourceBundle ValidatorMessages not found in thread context classloader
    21:16:31,542 DEBUG ClassValidator:170 - ResourceBundle ValidatorMessages not found in Validator classloader. Delegate to org.hibernate.validator.resources.DefaultValidatorMessages
    21:16:31,567 INFO TableMetadata:40 - table found: PUBLIC.TEST
    21:16:31,567 INFO TableMetadata:41 - columns: [id, title, version]
    21:16:31,567 INFO TableMetadata:43 - foreign keys: []
    21:16:31,567 INFO TableMetadata:44 - indexes: [sys_idx_sys_ct_71_74, sys_idx_72]
    21:16:31,567 INFO SchemaUpdate:160 - schema update complete
    21:16:31,574 TRACE DriverManagerConnectionProvider:129 - returning connection to pool, pool size: 1
    21:16:31,574 DEBUG SessionFactoryImpl:390 - Checking 0 named HQL queries
    21:16:31,574 DEBUG SessionFactoryImpl:410 - Checking 0 named SQL queries
    21:16:31,620 DEBUG SessionImpl:220 - opened session at timestamp: 12106197915
    21:16:31,623 TRACE VersionValue:44 - version unsaved-value strategy UNDEFINED
    21:16:31,623 TRACE IdentifierValue:104 - id unsaved-value: 0
    21:16:31,623 TRACE AbstractSaveEventListener:489 - transient instance of: org.jtheque.tests.techno.jpa.TestEntity
    21:16:31,623 TRACE DefaultPersistEventListener:124 - saving transient instance
    21:16:31,626 TRACE AbstractSaveEventListener:152 - saving [org.jtheque.tests.techno.jpa.TestEntity#<null>]
    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.tests.techno.jpa.JPATest.main(JPATest.java:59)
    21:16:31,629 TRACE SessionImpl:273 - closing session
    21:16:31,629 TRACE ConnectionManager:369 - connection already null in cleanup : no action
    21:16:31,629 INFO SessionFactoryImpl:767 - closing
    21:16:31,630 INFO DriverManagerConnectionProvider:147 - cleaning up connection pool: jdbc:hsqldb:hsql://localhost/dvd
    Je pense que ça doit venir de la configuration de JPA/Hibernate, mais je ne voiis pas ce que j'ai fait faux

    Quelqu'un a t'il une idée ?

  4. #4
    Expert confirmé
    Avatar de Baptiste Wicht
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2005
    Messages
    7 431
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Suisse

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2005
    Messages : 7 431
    Par défaut
    J'ai continué à chercher et j'ai essayé en utilisant un fichier de mapping :

    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
     
    public class JPATest extends AbstractTest{
    	public static void main(String... args){
    		LogManager logManager = LogManager.getInstance();
    		logManager.init();
     
    		Server hsqlServer = null;
    		try {
                hsqlServer =(Server) Class.forName("org.hsqldb.Server").newInstance();
     
                PrintWriter writer = new PrintWriter(new ServerLogWriter(hsqlServer.getClass()));
     
                hsqlServer.setLogWriter(writer);
                hsqlServer.setErrWriter(writer);
                hsqlServer.setDatabasePath(0, "localhost/dvd");
                hsqlServer.setDatabaseName(0, "dvd");
                hsqlServer.start();
            } catch (Exception e1) {
                e1.printStackTrace();
            }
     
            EntityManagerFactory emf = Persistence.createEntityManagerFactory("jpa");
     
    		EntityManager em = emf.createEntityManager();
     
    		em.getTransaction().begin();
     
    		TestEntity entity = new TestEntity();
    		entity.setTitle("JPA-3");
     
    		try{
    			em.persist(entity);
    		} catch(NullPointerException e){
    			e.printStackTrace();
    		}
     
    		em.getTransaction().commit();
     
    		em.close();
     
    		emf.close();
     
    		hsqlServer.stop();
     
    		logManager.close();
     
    		System.exit(0);
    	}
    }
    Code XML : 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
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence">
    	<persistence-unit name="jpa" transaction-type="RESOURCE_LOCAL">
    		<!--  provider -->
    		<provider>org.hibernate.ejb.HibernatePersistence</provider>
     
    		<!-- Classes persistantes -->
            <class>org.jtheque.tests.techno.jpa.TestEntity</class>
     
    		<properties>
    			<property name="hibernate.show_sql" value="true"/>
    			<property name="hibernate.format_sql" value="true"/>
    			<property name="use_sql_comments" value="false"/>
     
    			<!-- connexion JDBC -->
    			<property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver" />
    			<property name="hibernate.connection.url" value="jdbc:hsqldb:hsql://localhost/dvd" />
    			<property name="hibernate.connection.username" value="sa" />
    			<property name="hibernate.connection.password" value="" />
     
    			<!-- Dialecte -->
    			<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
     
    			<property name="hibernate.hbm2ddl.auto" value="update" />
     
    			<!-- propriétés DataSource c3p0
    			<property name="hibernate.c3p0.min_size" value="5" />
    			<property name="hibernate.c3p0.max_size" value="20" />
    			<property name="hibernate.c3p0.timeout" value="500" />
    			<property name="hibernate.c3p0.max_statements" value="100" />
    			<property name="hibernate.c3p0.idle_test_period" value="5000" /> -->
    		</properties>
    	</persistence-unit>
    </persistence>

    Et cette fois ça marche...

    J'ai exactement les même paramètres dans le fichier et dans EJB3Configuration, mais ça doit pas marcher de la même manière

  5. #5
    Expert confirmé
    Avatar de Baptiste Wicht
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2005
    Messages
    7 431
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Suisse

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2005
    Messages : 7 431
    Par défaut
    Bon, cette fois, j'ai réussi. J'ai laissé le fichier persistence.xml et j'utilise EJB3Configuration pour aller chercher les propriétés dans le fichier.

    J'ai juste encore un problème. Voici ce qu'il me donne durant l'éxécution :

    14:53:41,811 DEBUG Ejb3Configuration:522 - Detect class: true; detect hbm: true
    14:53:41,827 DEBUG JarVisitor:192 - Searching mapped entities in jar/par: file:/D:/Programmation/Workspaces/Eclipse%20Workspace/JTheque/bin
    14:53:41,827 WARN FileZippedJarVisitor:37 - Unable to find file (ignored): file:/D:/Programmation/Workspaces/Eclipse%20Workspace/JTheque/bin
    java.io.FileNotFoundException: D:\Programmation\Workspaces\Eclipse Workspace\JTheque\bin (Access is denied)
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.<init>(Unknown Source)
    at java.util.jar.JarFile.<init>(Unknown Source)
    at java.util.jar.JarFile.<init>(Unknown Source)
    at org.hibernate.ejb.packaging.FileZippedJarVisitor.doProcessElements(FileZippedJarVisitor.java:34)
    at org.hibernate.ejb.packaging.JarVisitor.getMatchingEntries(JarVisitor.java:215)
    at org.hibernate.ejb.Ejb3Configuration.addMetadataFromVisitor(Ejb3Configuration.java:253)
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:229)
    at org.jtheque.tests.techno.jpa.JPATest.main(JPATest.java:38)
    14:53:41,827 DEBUG Ejb3Configuration:522 - Detect class: true; detect hbm: true
    Il a l'air d'essayer de chercher d'autres classes persistantes. C'est possible de désactiver cette recheche automatique ?

Discussions similaires

  1. NullPointerException lors d'un resultset.next()
    Par theophanie dans le forum JDBC
    Réponses: 10
    Dernier message: 10/08/2010, 14h20
  2. Réponses: 3
    Dernier message: 10/06/2008, 19h58
  3. Réponses: 8
    Dernier message: 14/05/2008, 12h15
  4. Réponses: 0
    Dernier message: 26/12/2007, 18h28
  5. [EJB3 Entity] NullPointerException lors d'appel persist
    Par tiamat dans le forum Java EE
    Réponses: 21
    Dernier message: 17/10/2007, 15h37

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo