-->
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.  [ 3 posts ] 
Author Message
 Post subject: enum within a class causes illegalAccessException
PostPosted: Thu Dec 13, 2007 6:54 pm 
Newbie

Joined: Thu Dec 13, 2007 6:16 pm
Posts: 2
I am using Hibernate 3 with Annotations and got a problem mapping enums.
I have declared an enum. This enum is used as a type in another class for a single variable.
The variable is mapped into its own column as a number or a string, depending how I specify the mapping - and it works wonderful!

Everything works excellent as long as I keep the enum IN A SEPARATE java-file. When I use an inner enum, which makes logically sense because it belongs exactly to this one class, I get an IllegalAccessExceptionException when I try to export the schema to the MySql database.

The message passed by the exception is 'Class org.hibernate.type.EnumType can not access a member of class erm.enumeration.TK1 with modifiers "public static"' (TK1 is the enum type).

Why must the enum be in a separate file ? Did I oversee something ?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 15, 2007 9:50 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I would appreciate a test case, can you post it to JIRA

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 16, 2007 1:03 pm 
Newbie

Joined: Thu Dec 13, 2007 6:16 pm
Posts: 2
Thank you for your quick reply, emmanuel.
Fortunately, I found the reason for the exception - it was just my error!

I forgot to mark the inner class (the enum) to be public.
This is the (reduced) corrected code:

Code:
@Entity
public class Transport {
 
   public static enum TKind{
    SHIP,
    PLANE;
    };
  }

@Id
long pk;

  TKind kind; // enum must be public
.....


If I do not mark the inner class as being public I receive the exception. What was a bit irritating was the exception message itself which stated

can not access a member of class enumeration.TKind with modifiers "public static".

In fact the enum MUST be public static. However, Hibernate stays the most important and fascinating tool for me for more than 5 years now! That's why my students have to learn hibernate.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.