Hello, I'm using some third party legacy classes and I'm having problems using the deepCopy method of the HibernateReplicator class.
Basically here is a simple case:
public class MainClass {
public static void main(String[] args) { MainClass m = new MainClass(); m.test(); }
public void test(){ A from = new A(); from.setAction(EnumAction.UNKNOWN); HibernateBeanReplicator replicator = new Hibernate3BeanReplicator(); A copy = replicator.deepCopy(from); System.out.println("Copy is:" + copy); }
}
It fails instantiating EnumAction (class definition below), with the following exception:
/**********************************************************************
Exception in thread "main" net.sf.beanlib.BeanlibException: java.lang.NoSuchMethodException: test.enumeration.EnumAction.<init>() at net.sf.beanlib.provider.replicator.BeanReplicator.replicateBean(BeanReplicator.java:134) at net.sf.beanlib.hibernate3.Hibernate3JavaBeanReplicator.replicateBean(Hibernate3JavaBeanReplicator.java:71) - Caused by: java.lang.NoSuchMethodException: test.enumeration.EnumAction.<init>()
***************END EXCEPTION STACK *************************/
package test.enumeration;
import java.io.Serializable;
public abstract class Enum implements Serializable{
private static final long serialVersionUID = 1L; /** * Description of this Enum instance */ protected final String description;
/** * Natural ordering number for the Enum */ protected int ordinal;
/** * Protected constructor with no description. * * @param ordinal the natural ordering number */ protected Enum( int ordinal ) { this( ordinal, null ); } /** * Protected constructor. * * @param ordinal the natural ordering number * @param description informative description string */ protected Enum( int ordinal, String description ) {
this.description = ( description == null ? getClass().getName() + ordinal : description ); this.ordinal = ordinal; }
=============================================================================
public class EnumAction extends Enum { private static final long serialVersionUID = 1; private static final Map stringMap = new HashMap(); private static final Map ordMap = new HashMap();
public static final int UNKNOWN_ORD = -1; public static final String UNKNOWN_STR = "UNKNOWN";
public static final EnumAction UNKNOWN = new EnumAction(UNKNOWN_ORD, UNKNOWN_STR); public static final EnumAction FASTACTION = new EnumAction(1, "FASTACTION"); protected EnumAction(int ordinal, String description) { super(ordinal, description); if (stringMap.containsKey(description)) { throw new RuntimeException("Duplicate string in EnumAction enum: " + description); } Integer intOrdinal = new Integer(ordinal); if (ordMap.containsKey(intOrdinal)) { throw new RuntimeException("Duplicate ordinal in EnumAction enum: " + ordinal); } stringMap.put(description,this); ordMap.put(intOrdinal,this); } }
public class A { private EnumAction action = EnumAction.UNKNOWN; public String toString(){ System.out.println("Object A: => action is:" + action); return action.toString(); }
public EnumAction getAction() { return action; }
public void setAction(EnumAction action) { this.action = action; }
Please see the reply I posted to Beanlib Google Groups:
http://groups.google.com/group/beanlib/browse_thread/thread/c30fdac9b2f547fd#
Cheers, Hanson
Log in to post a comment.
Hello, I'm using some third party legacy classes and I'm having problems using the deepCopy method of the HibernateReplicator class.
Basically here is a simple case:
public class MainClass {
public static void main(String[] args) {
MainClass m = new MainClass();
m.test();
}
public void test(){
A from = new A();
from.setAction(EnumAction.UNKNOWN);
HibernateBeanReplicator replicator = new Hibernate3BeanReplicator();
A copy = replicator.deepCopy(from);
System.out.println("Copy is:" + copy);
}
}
It fails instantiating EnumAction (class definition below), with the following exception:
/**********************************************************************
Exception in thread "main" net.sf.beanlib.BeanlibException: java.lang.NoSuchMethodException: test.enumeration.EnumAction.<init>()
at net.sf.beanlib.provider.replicator.BeanReplicator.replicateBean(BeanReplicator.java:134)
at net.sf.beanlib.hibernate3.Hibernate3JavaBeanReplicator.replicateBean(Hibernate3JavaBeanReplicator.java:71)
-
Caused by: java.lang.NoSuchMethodException: test.enumeration.EnumAction.<init>()
***************END EXCEPTION STACK *************************/
package test.enumeration;
import java.io.Serializable;
public abstract class Enum implements Serializable{
private static final long serialVersionUID = 1L;
/**
* Description of this Enum instance
*/
protected final String description;
/**
* Natural ordering number for the Enum
*/
protected int ordinal;
/**
* Protected constructor with no description.
*
* @param ordinal the natural ordering number
*/
protected Enum( int ordinal ) {
this( ordinal, null );
}
/**
* Protected constructor.
*
* @param ordinal the natural ordering number
* @param description informative description string
*/
protected Enum( int ordinal, String description ) {
this.description = ( description == null ?
getClass().getName() + ordinal :
description );
this.ordinal = ordinal;
}
}
=============================================================================
public class EnumAction extends Enum
{
private static final long serialVersionUID = 1;
private static final Map stringMap = new HashMap();
private static final Map ordMap = new HashMap();
public static final int UNKNOWN_ORD = -1;
public static final String UNKNOWN_STR = "UNKNOWN";
public static final EnumAction UNKNOWN = new EnumAction(UNKNOWN_ORD, UNKNOWN_STR);
public static final EnumAction FASTACTION = new EnumAction(1, "FASTACTION");
protected EnumAction(int ordinal, String description)
{
super(ordinal, description);
if (stringMap.containsKey(description)) {
throw new RuntimeException("Duplicate string in EnumAction enum: " + description);
}
Integer intOrdinal = new Integer(ordinal);
if (ordMap.containsKey(intOrdinal)) {
throw new RuntimeException("Duplicate ordinal in EnumAction enum: " + ordinal);
}
stringMap.put(description,this);
ordMap.put(intOrdinal,this);
}
}
public class A {
private EnumAction action = EnumAction.UNKNOWN;
public String toString(){
System.out.println("Object A: => action is:" + action);
return action.toString();
}
public EnumAction getAction() {
return action;
}
public void setAction(EnumAction action) {
this.action = action;
}
}
Please see the reply I posted to Beanlib Google Groups:
http://groups.google.com/group/beanlib/browse_thread/thread/c30fdac9b2f547fd#
Cheers,
Hanson