List of usage examples for org.hibernate.internal.util ReflectHelper getDefaultConstructor
public static <T> Constructor<T> getDefaultConstructor(Class<T> clazz) throws PropertyNotFoundException
From source file:org.web4thejob.orm.AbstractHibernateEntity.java
License:Open Source License
@SuppressWarnings("CloneDoesntCallSuperClone") @Override//ww w . j a va 2 s. co m public Entity clone() { try { final Entity clone = (Entity) ReflectHelper.getDefaultConstructor(getClass()) .newInstance((Object[]) null); clone.addDirtyListener(dirtyListener); ReflectionUtils.doWithFields(getClass(), new ReflectionUtils.FieldCallback() { @Override public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException { ReflectionUtils.makeAccessible(field); if (!Collection.class.isAssignableFrom(field.getType())) { // don't clone one-to-many fields field.set(clone, field.get(AbstractHibernateEntity.this)); } } }, ReflectionUtils.COPYABLE_FIELDS); return clone; } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("Clone failed for " + toString(), e); } }
From source file:org.web4thejob.orm.MetaReaderServiceImpl.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public <E extends Entity> E newInstance(Class<? extends Entity> entityType) { try {//from w w w. ja v a2 s . com if (entityType.isInterface()) { entityType = getEntityMetadata(entityType).getMappedClass(); } return (E) ReflectHelper.getDefaultConstructor(entityType).newInstance((Object[]) null); } catch (final Exception e) { e.printStackTrace(); return null; } }