I'd be happy to provide a fix, I'm just not sure if it's something that needs to be fixed or if it should behave this way by design.
I'm not using
CustomType directly but this is where the exception crops up. I'm implementing
UserType so I can persist a typesafe enumeration, as described in this link:
UserType for persisting a Typesafe Enumeration with a VARCHAR column.
So I have a persistent Enum base class:
Code:
public abstract class Enum implements Serializable, Comparable, UserType {
// default constructor for hibernate
protected Enum() {
super();
}
// implement the interfaces...
}
And a concrete typesafe enumeration:
Code:
public final class ProvisioningState extends Enum {
// default constructor for hibernate
private ProvisioningState() {
super();
}
private ProvisioningState(int ordinal, String name) {
super(ordinal, name);
}
public static final ProvisioningState FOO = new ProvisioningState(0, "Foo");
public static final ProvisioningState BAR = new ProvisioningState(1, "Bar");
}
I would like the constructors to remain non-public to prevent a user of this class from instantiating it.
The (interesting part of the) stack trace I get:
[java] 2004-11-30 10:29:15,495 ERROR (Configuration.java:255) - Could not compile the mapping documentnet.sf.hibernate.MappingException: IllegalAccessException trying to instantiate custom type: com.mycompany.ProvisioningState
[java] at net.sf.hibernate.type.CustomType.<init>(CustomType.java:41)
[java] at net.sf.hibernate.type.TypeFactory.heuristicType(TypeFactory.java:163)
[java] at net.sf.hibernate.cfg.Binder.getTypeFromXML(Binder.java:933)
[java] at net.sf.hibernate.cfg.Binder.bindSimpleValue(Binder.java:435)
[java] at net.sf.hibernate.cfg.Binder.propertiesFromXML(Binder.java:1047)
[java] at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:362)
[java] at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1256)
[java] at net.sf.hibernate.cfg.Configuration.add(Configuration.java:252)
[java] at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:288)
[java] at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:336)
[java] at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:1013)
[java] at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:969)
[java] at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:931)