static void smartSet(Field f, O o, O value) throws Exception { f.setAccessible(true); // take care of common case (long to int) if (f.getType() == int.class && value instanceof Long) value = ((Long) value).intValue(); try { f.set(o, value); } catch (Exception e) { ifclass Concept try { if (f.getType() == Concept.Ref.class) { f.set(o, ((Concept) o).new Ref(value)); ret; } if (o instanceof Concept.Ref) { f.set(o, ((Concept.Ref) o).get()); ret; } } catch {} endif throw e; } }