Erreur "org.hibernate.HibernateException: get is not valid without active transaction"
Bonjour,
J'ai une erreur quand j'essai d'utiliser les classes généré par hibernate tools, depuis deux jours j'essai de faire marcher et c'est que erreur après erreur :
Voici l'exception :
Code:
1 2 3 4 5 6
| Exception in thread "main" org.hibernate.HibernateException: get is not valid without active transaction
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:268)
at $Proxy0.get(Unknown Source)
at adhoc.erp.wr.persistence.ImputationHome.findById(ImputationHome.java:98)
at adhoc.erp.wr.persistence.ImputationHomeTest.main(ImputationHomeTest.java:8)
2011-07-29 13:56:34 ImputationHome [ERROR] get failed |
Mon fichier hibernate.cfg.xml :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="java:hibernate/SessionFactory">
<property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/mydb</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="current_session_context_class">thread</property>
<!-- Mapping files -->
<mapping resource="adhoc/erp/wr/persistence/mapping/Consultant.hbm.xml" />
<mapping resource="adhoc/erp/wr/persistence/mapping/Customer.hbm.xml" />
<mapping resource="adhoc/erp/wr/persistence/mapping/Imputation.hbm.xml" />
<mapping resource="adhoc/erp/wr/persistence/mapping/Project.hbm.xml" />
<mapping resource="adhoc/erp/wr/persistence/mapping/Task.hbm.xml" />
</session-factory>
</hibernate-configuration> |
Le log en entier :
Code:
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
| 2011-07-29 13:56:33 Environment [INFO] Hibernate 3.1 rc2
2011-07-29 13:56:33 Environment [INFO] hibernate.properties not found
2011-07-29 13:56:33 Environment [INFO] using CGLIB reflection optimizer
2011-07-29 13:56:33 Environment [INFO] using JDK 1.4 java.sql.Timestamp handling
2011-07-29 13:56:33 Configuration [INFO] configuring from resource: /hibernate.cfg.xml
2011-07-29 13:56:33 Configuration [INFO] Configuration resource: /hibernate.cfg.xml
2011-07-29 13:56:33 Configuration [INFO] Reading mappings from resource: adhoc/erp/wr/persistence/mapping/Consultant.hbm.xml
2011-07-29 13:56:33 HbmBinder [INFO] Mapping class: adhoc.erp.wr.persistence.Consultant -> consultant
2011-07-29 13:56:33 Configuration [INFO] Reading mappings from resource: adhoc/erp/wr/persistence/mapping/Customer.hbm.xml
2011-07-29 13:56:33 HbmBinder [INFO] Mapping class: adhoc.erp.wr.persistence.Customer -> customer
2011-07-29 13:56:33 Configuration [INFO] Reading mappings from resource: adhoc/erp/wr/persistence/mapping/Imputation.hbm.xml
2011-07-29 13:56:33 HbmBinder [INFO] Mapping class: adhoc.erp.wr.persistence.Imputation -> imputation
2011-07-29 13:56:33 Configuration [INFO] Reading mappings from resource: adhoc/erp/wr/persistence/mapping/Project.hbm.xml
2011-07-29 13:56:33 HbmBinder [INFO] Mapping class: adhoc.erp.wr.persistence.Project -> project
2011-07-29 13:56:33 Configuration [INFO] Reading mappings from resource: adhoc/erp/wr/persistence/mapping/Task.hbm.xml
2011-07-29 13:56:33 HbmBinder [INFO] Mapping class: adhoc.erp.wr.persistence.Task -> task
2011-07-29 13:56:33 Configuration [INFO] Configured SessionFactory: java:hibernate/SessionFactory
2011-07-29 13:56:33 Configuration [INFO] processing extends queue
2011-07-29 13:56:33 Configuration [INFO] processing collection mappings
2011-07-29 13:56:33 Configuration [INFO] processing association property references
2011-07-29 13:56:33 Configuration [INFO] processing foreign key constraints
2011-07-29 13:56:33 DriverManagerConnectionProvider [INFO] Using Hibernate built-in connection pool (not for production use!)
2011-07-29 13:56:33 DriverManagerConnectionProvider [INFO] Hibernate connection pool size: 10
2011-07-29 13:56:33 DriverManagerConnectionProvider [INFO] autocommit mode: false
2011-07-29 13:56:33 DriverManagerConnectionProvider [INFO] using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://localhost:3306/mydb
2011-07-29 13:56:33 DriverManagerConnectionProvider [INFO] connection properties: {user=root, password=****}
2011-07-29 13:56:33 SettingsFactory [INFO] RDBMS: MySQL, version: 5.5.13-log
2011-07-29 13:56:33 SettingsFactory [INFO] JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.17 ( Revision: ${bzr.revision-id} )
2011-07-29 13:56:33 Dialect [INFO] Using dialect: org.hibernate.dialect.MySQLDialect
2011-07-29 13:56:33 TransactionFactoryFactory [INFO] Using default transaction strategy (direct JDBC transactions)
2011-07-29 13:56:33 TransactionManagerLookupFactory [INFO] No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
2011-07-29 13:56:33 SettingsFactory [INFO] Automatic flush during beforeCompletion(): disabled
2011-07-29 13:56:33 SettingsFactory [INFO] Automatic session close at end of transaction: disabled
2011-07-29 13:56:33 SettingsFactory [INFO] JDBC batch size: 15
2011-07-29 13:56:33 SettingsFactory [INFO] JDBC batch updates for versioned data: disabled
2011-07-29 13:56:33 SettingsFactory [INFO] Scrollable result sets: enabled
2011-07-29 13:56:33 SettingsFactory [INFO] JDBC3 getGeneratedKeys(): enabled
2011-07-29 13:56:33 SettingsFactory [INFO] Connection release mode: auto
2011-07-29 13:56:33 SettingsFactory [INFO] Maximum outer join fetch depth: 2
2011-07-29 13:56:33 SettingsFactory [INFO] Default batch fetch size: 1
2011-07-29 13:56:33 SettingsFactory [INFO] Generate SQL with comments: disabled
2011-07-29 13:56:33 SettingsFactory [INFO] Order SQL updates by primary key: disabled
2011-07-29 13:56:33 SettingsFactory [INFO] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
2011-07-29 13:56:34 ASTQueryTranslatorFactory [INFO] Using ASTQueryTranslatorFactory
2011-07-29 13:56:34 SettingsFactory [INFO] Query language substitutions: {}
2011-07-29 13:56:34 SettingsFactory [INFO] Second-level cache: enabled
2011-07-29 13:56:34 SettingsFactory [INFO] Query cache: disabled
2011-07-29 13:56:34 SettingsFactory [INFO] Cache provider: org.hibernate.cache.EhCacheProvider
2011-07-29 13:56:34 SettingsFactory [INFO] Optimize cache for minimal puts: disabled
2011-07-29 13:56:34 SettingsFactory [INFO] Structured second-level cache entries: disabled
2011-07-29 13:56:34 SettingsFactory [INFO] Echoing all SQL to stdout
2011-07-29 13:56:34 SettingsFactory [INFO] Statistics: disabled
2011-07-29 13:56:34 SettingsFactory [INFO] Deleted entity synthetic identifier rollback: disabled
2011-07-29 13:56:34 SettingsFactory [INFO] Default entity-mode: POJO
2011-07-29 13:56:34 SessionFactoryImpl [INFO] building session factory
2011-07-29 13:56:34 Configurator [WARN] No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Users/benjelloun/.m2/repository/ehcache/ehcache/1.1/ehcache-1.1.jar!/ehcache-failsafe.xml
2011-07-29 13:56:34 SessionFactoryObjectFactory [INFO] Factory name: java:hibernate/SessionFactory
2011-07-29 13:56:34 NamingHelper [INFO] JNDI InitialContext properties:{}
2011-07-29 13:56:34 SessionFactoryObjectFactory [WARN] Could not bind factory to JNDI
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getNameParser(Unknown Source)
at org.hibernate.util.NamingHelper.bind(NamingHelper.java:52)
at org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:90)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:293)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1145)
at adhoc.erp.wr.persistence.ImputationHome.getSessionFactory(ImputationHome.java:28)
at adhoc.erp.wr.persistence.ImputationHome.<init>(ImputationHome.java:24)
at adhoc.erp.wr.persistence.ImputationHomeTest.main(ImputationHomeTest.java:7)
2011-07-29 13:56:34 SchemaUpdate [INFO] Running hbm2ddl schema update
2011-07-29 13:56:34 SchemaUpdate [INFO] fetching database metadata
2011-07-29 13:56:34 SchemaUpdate [INFO] updating schema
2011-07-29 13:56:34 Configuration [INFO] processing extends queue
2011-07-29 13:56:34 Configuration [INFO] processing collection mappings
2011-07-29 13:56:34 Configuration [INFO] processing association property references
2011-07-29 13:56:34 Configuration [INFO] processing foreign key constraints
2011-07-29 13:56:34 TableMetadata [INFO] table found: mydb.consultant
2011-07-29 13:56:34 TableMetadata [INFO] columns: [phone, adress, lastname, idconsultant, firstname]
2011-07-29 13:56:34 TableMetadata [INFO] foreign keys: []
2011-07-29 13:56:34 TableMetadata [INFO] indexes: [primary]
2011-07-29 13:56:34 TableMetadata [INFO] table found: mydb.customer
2011-07-29 13:56:34 TableMetadata [INFO] columns: [idcustomer, customername]
2011-07-29 13:56:34 TableMetadata [INFO] foreign keys: []
2011-07-29 13:56:34 TableMetadata [INFO] indexes: [primary]
2011-07-29 13:56:34 TableMetadata [INFO] table found: mydb.imputation
2011-07-29 13:56:34 TableMetadata [INFO] columns: [idtask, nbhours, idconsultant, date, idimputation]
2011-07-29 13:56:34 TableMetadata [INFO] foreign keys: []
2011-07-29 13:56:34 TableMetadata [INFO] indexes: [primary]
2011-07-29 13:56:34 TableMetadata [INFO] table found: mydb.project
2011-07-29 13:56:34 TableMetadata [INFO] columns: [idcustomer, idproject, projectname]
2011-07-29 13:56:34 TableMetadata [INFO] foreign keys: []
2011-07-29 13:56:34 TableMetadata [INFO] indexes: [primary]
2011-07-29 13:56:34 TableMetadata [INFO] table found: mydb.task
2011-07-29 13:56:34 TableMetadata [INFO] columns: [idtask, idproject, taskname]
2011-07-29 13:56:34 TableMetadata [INFO] foreign keys: []
2011-07-29 13:56:34 TableMetadata [INFO] indexes: [primary]
2011-07-29 13:56:34 SchemaUpdate [INFO] schema update complete
2011-07-29 13:56:34 DriverManagerConnectionProvider [INFO] cleaning up connection pool: jdbc:mysql://localhost:3306/mydb
2011-07-29 13:56:34 SessionFactoryImpl [INFO] Checking 0 named queries
Exception in thread "main" org.hibernate.HibernateException: get is not valid without active transaction
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:268)
at $Proxy0.get(Unknown Source)
at adhoc.erp.wr.persistence.ImputationHome.findById(ImputationHome.java:98)
at adhoc.erp.wr.persistence.ImputationHomeTest.main(ImputationHomeTest.java:8)
2011-07-29 13:56:34 ImputationHome [ERROR] get failed
org.hibernate.HibernateException: get is not valid without active transaction
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:268)
at $Proxy0.get(Unknown Source)
at adhoc.erp.wr.persistence.ImputationHome.findById(ImputationHome.java:98)
at adhoc.erp.wr.persistence.ImputationHomeTest.main(ImputationHomeTest.java:8) |
cette fois j'ai un peu d'espoir d'avoir une réponse :cry: