-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 
Author Message
 Post subject: Illegal Access error
PostPosted: Wed Mar 21, 2007 2:01 pm 
Newbie

Joined: Wed Mar 21, 2007 1:12 pm
Posts: 19
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.2

Mapping documents: persistence.xml

<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">
</persistence-unit>
</persistence>

Code to persist object:

Map<String,String> myProperties = new HashMap<String,String>();
myProperties.put("hibernate.hbm2ddl.auto", "create-drop");
myProperties.put("hibernate.archive.autodetection" , "class");
myProperties.put("hibernate.connection.driver_class" , "org.gjt.mm.mysql.Driver");
myProperties.put("hibernate.connection.password" , "");
myProperties.put("hibernate.connection.url" , "jdbc:mysql://localhost");
myProperties.put("hibernate.connection.username" , "ruya");
myProperties.put("hibernate.default_schema" , "mater");
myProperties.put("hibernate.dialect" , "org.hibernate.dialect.MySQLDialect");
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("mater_persistence", myProperties );
// First unit of work
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();

em.persist(model);

tx.commit();
em.close();

Full stack trace of any exception that occurs:

Exception in thread "main" java.lang.IllegalAccessError
at net.sf.cglib.core.ClassEmitter.setTarget(ClassEmitter.java:45)
at net.sf.cglib.core.ClassEmitter.<init>(ClassEmitter.java:37)
at net.sf.cglib.core.KeyFactory$Generator.generateClass(KeyFactory.java:165)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:145)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:117)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:69)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:107)
at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:43)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:162)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:135)
at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:56)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:295)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:713)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)


Name and version of the database you are using: MySQL 5.0


Top
 Profile  
 
 Post subject: How to seek
PostPosted: Thu Mar 22, 2007 6:54 am 
Newbie

Joined: Wed Mar 21, 2007 1:12 pm
Posts: 19
Hi,
I posted this problem yesterday and nobody answered (yet, I hope).
Can someone point me a way to found a solution or, at least, to get to the root of the problem?

Thanks,
Rui


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 22, 2007 11:13 am 
Newbie

Joined: Wed Mar 21, 2007 1:12 pm
Posts: 19
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 22, 2007 5:05 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
it's usually due to:
- not enough JVM privileges
- or more frequently a wrongly formed getter (wrong type, wrong signature)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 22, 2007 11:15 pm 
Newbie

Joined: Wed Mar 21, 2007 1:12 pm
Posts: 19
Hi,

Thanks. Now, if I have only one class with the

@Id
Long id;

(...)
Long getId();
void setId(Long);
(...)

and all other fields annotated with @Transient, then it sure is a question of jvm priveleges, right?

Thanks,
Rui


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 23, 2007 10:25 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
sounds like, ah be sure to have a no arg constructor (package level or above) and no final class nor final methods

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 23, 2007 11:59 am 
Newbie

Joined: Wed Mar 21, 2007 1:12 pm
Posts: 19
Hi,

I didn't understand what you meant by package level or above constructor but the class I want to persist has a default constructor. I don't have final classes nor final methods. I do have, although, nested classes and final fields, yet marked with @Transient. It is something like this:
Code:
package mypackage;

public class ToPersist{

@Id
private Long id;
@Transient
private final String[] finalStringArray;

(...)
public ToPersist(){}

(...)
public Long getId(){...}
public void setId(Long){...}
(...)

class NestedClass1(){...}
(...)
}




Is this ok? Do I need to explicitly exclude the nested classes?

Thanks,
Rui[


Top
 Profile  
 
 Post subject: Now, the permissions
PostPosted: Fri Mar 23, 2007 12:41 pm 
Newbie

Joined: Wed Mar 21, 2007 1:12 pm
Posts: 19
What type of permissions are we talking about?
I tried to set a SecurityManager to my application using a policy file which grants AllPermission, but this way hibernate couldn't find the persistence provider.
By default java applications don't have a security manager because usually it is not needed. Shouldn't this be ok for hibernate?

Rui


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 23, 2007 1:18 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
try and remove the final

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 23, 2007 1:55 pm 
Newbie

Joined: Wed Mar 21, 2007 1:12 pm
Posts: 19
I removed the final field but it has the same exception building the session factory.

Rui


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.