I have done it again, this time using the persistence.xml file instead of doing it programmatically.
The persistence fie:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/ ... ce_1_0.xsd"
version="1.0">
<persistence-unit name="mater_persistence">
<!--
<provider value="org.hibernate.ejb.HibernatePersistence"/>
-->
<properties>
<!-- Scan for annotated classes and Hibernate mapping XML files -->
<property name="hibernate.archive.autodetection" value="class, hbm"/>
<!-- SQL stdout logging
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="use_sql_comments" value="true"/>
-->
<property name="hibernate.connection.driver_class" value="org.gjt.mm.mysql.Driver"/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost"/>
<property name="hibernate.connection.username" value="ruya"/>
<property name="hibernate.default_schema" value="mater"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
</properties>
</persistence-unit>
</persistence>
Code to persiste object:
1. EntityManagerFactory emf = Persistence.createEntityManagerFactory("mater_persistence" );
2. EntityManager em = emf.createEntityManager();
3. EntityTransaction tx = em.getTransaction();
4. tx.begin();
5. em.persist(model);
6. tx.commit();
7. em.close();
The hibernate info output:
15:05:06,478 INFO Version:148 - Hibernate EntityManager 3.2.1.GA
15:05:06,499 INFO Version:148 - Hibernate Annotations 3.2.1.GA
15:05:06,615 INFO Environment:148 - Hibernate 3.2.2
15:05:06,619 INFO Environment:148 - hibernate.properties not found
15:05:06,622 INFO Environment:148 - Bytecode provider name : cglib
15:05:06,627 INFO Environment:148 - using JDK 1.4 java.sql.Timestamp handling
15:05:07,514 INFO AnnotationBinder:148 - Binding entity from annotated class: mater.MaterModel
15:05:07,555 INFO EntityBinder:148 - Bind entity mater.MaterModel on table MaterModel
15:05:07,751 INFO DriverManagerConnectionProvider:148 - Using Hibernate built-in connection pool (not for production use!)
15:05:07,751 INFO DriverManagerConnectionProvider:148 - Hibernate connection pool size: 20
15:05:07,752 INFO DriverManagerConnectionProvider:148 - autocommit mode: true
15:05:07,762 INFO DriverManagerConnectionProvider:148 - using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://localhost
15:05:07,762 INFO DriverManagerConnectionProvider:148 - connection properties: {user=ruya, password=****, autocommit=true, release_mode=auto}
15:05:08,014 INFO SettingsFactory:148 - RDBMS: MySQL, version: 5.0.24a-Debian_9-log
15:05:08,015 INFO SettingsFactory:148 - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.0.5 ( $Date: 2007-03-01 00:01:06 +0100 (Thu, 01 Mar 2007) $, $Revision: 6329 $ )
15:05:08,031 INFO Dialect:148 - Using dialect: org.hibernate.dialect.MySQLDialect
15:05:08,036 INFO TransactionFactoryFactory:148 - Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
15:05:08,038 INFO TransactionManagerLookupFactory:148 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
15:05:08,038 INFO SettingsFactory:148 - Automatic flush during beforeCompletion(): disabled
15:05:08,039 INFO SettingsFactory:148 - Automatic session close at end of transaction: disabled
15:05:08,039 INFO SettingsFactory:148 - JDBC batch size: 15
15:05:08,039 INFO SettingsFactory:148 - JDBC batch updates for versioned data: disabled
15:05:08,041 INFO SettingsFactory:148 - Scrollable result sets: enabled
15:05:08,042 INFO SettingsFactory:148 - JDBC3 getGeneratedKeys(): enabled
15:05:08,042 INFO SettingsFactory:148 - Connection release mode: auto
15:05:08,043 INFO SettingsFactory:148 - Default schema: mater
15:05:08,043 INFO SettingsFactory:148 - Maximum outer join fetch depth: 2
15:05:08,044 INFO SettingsFactory:148 - Default batch fetch size: 1
15:05:08,044 INFO SettingsFactory:148 - Generate SQL with comments: disabled
15:05:08,044 INFO SettingsFactory:148 - Order SQL updates by primary key: disabled
15:05:08,045 INFO SettingsFactory:148 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
15:05:08,047 INFO ASTQueryTranslatorFactory:148 - Using ASTQueryTranslatorFactory
15:05:08,048 INFO SettingsFactory:148 - Query language substitutions: {}
15:05:08,048 INFO SettingsFactory:148 - JPA-QL strict compliance: enabled
15:05:08,049 INFO SettingsFactory:148 - Second-level cache: enabled
15:05:08,049 INFO SettingsFactory:148 - Query cache: disabled
15:05:08,049 INFO SettingsFactory:148 - Cache provider: org.hibernate.cache.NoCacheProvider
15:05:08,050 INFO SettingsFactory:148 - Optimize cache for minimal puts: disabled
15:05:08,050 INFO SettingsFactory:148 - Structured second-level cache entries: disabled
15:05:08,055 INFO SettingsFactory:148 - Statistics: disabled
15:05:08,056 INFO SettingsFactory:148 - Deleted entity synthetic identifier rollback: disabled
15:05:08,057 INFO SettingsFactory:148 - Default entity-mode: pojo
15:05:08,057 INFO SettingsFactory:148 - Named query checking : enabled
15:05:08,114 INFO SessionFactoryImpl:148 - building session factory
Exception in thread "main" java.lang.IllegalAccessError (at line 1 )
Can someone help me? I don't understand the reasons for the exception...
Thanks,
Rui