Model implements Getter,ValidatableBean,JsonStringable { public final <T extends Model> T set(String field,Object value){ _init(); if("id".equalsIgnoreCase(field) && null == em.tryGetFieldMapping(field)) { return id(value); }else{ doSet(field, value); return (T)this; } } Model(); @Instrument static T newInstance(); @Instrument static T newInstance(Object id); @Instrument static Object nextId(); @Instrument static InsertCommand cmdInsert(); @Instrument static UpdateCommand cmdUpdate(Object id); @Instrument static T create(Map<String, Object> fields); @Instrument static boolean update(Object id,Map<String, Object> fields); @Instrument static boolean update(Object id,String field,Object value); @Instrument static int updateAll(Map<String, Object> fields, String whereExpression, Object... args); @Instrument static void delete(Object id); @Instrument static boolean tryDelete(Object id); @Instrument static void cascadeDelete(Object id); @Instrument static boolean tryCascadeDelete(Object id); @Instrument static int deleteAll(); @Instrument static int[] deleteAll(Object[] ids); @Instrument static int deleteAll(String whereExpression); @Instrument static int deleteAll(String whereExpression,Object... args); @Instrument @SuppressWarnings("rawtypes") static int deleteAll(String whereExpression,Map<String, Object> params); @Instrument static int deleteBy(String field,Object value); @Instrument static int deleteBy(String field1, Object value1, String field2, Object value2); @Instrument static long count(); @Instrument static T find(Object id); @Instrument static T findOrNull(Object id); @Instrument static List<T> findList(Object[] ids); @Instrument static List<T> findListIfExists(Object[] ids); @Instrument static T findBy(String field,Object value); @Instrument static T findBy(String field1,Object value1, String field2, Object value2); @Instrument static List<T> findAll(); @Instrument static List<T> all(); @Instrument static T first(); @Instrument static List<T> first(int num); @Instrument static T firstOrNull(); @Instrument static T last(); @Instrument static List<T> last(int num); @Instrument static T lastOrNull(); @Instrument static List<T> lastCreated(int num); @Instrument static List<T> lastUpdated(int num); @Instrument static EntityQuery<T> query(String sqlOrKey); @Instrument static CriteriaQuery<T> query(); @Instrument static CriteriaWhere<T> where(); @Instrument static CriteriaQuery<T> where(String expression); @Instrument static CriteriaQuery<T> where(String expression,Object... args); @Instrument static CriteriaQuery<T> where(String expression,Map<String,Object> params); @Instrument static int[] createAll(Object[] records); @Instrument static int[] updateAll(Object[] records); @Instrument static void doTransaction(TransactionCallback callback); @Instrument static T doTransaction(TransactionCallbackWithResult<T> callback); @Instrument static void doTransaction(TransactionCallback callback, boolean requiresNew); @Instrument static T doTransaction(TransactionCallbackWithResult<T> callback, boolean requiresNew); @Instrument static Dao dao(); @Instrument static Dmo dmo(); @Instrument static EntityMapping metamodel(); @Instrument static Db db(); final void init(OrmContext context, EntityMapping em); final String getEntityName(); final EntityMapping getEntityMapping(); final boolean contains(String field); final Object get(String field); final Object get(Named field); String getString(String field); Integer getInteger(String field); Map<String, Object> fields(); Errors errors(); final Object id(); final T id(Object id); final T set(String field,Object value); final Timestamp createdAt(); final Timestamp updatedAt(); final T set(Named field,Object value); T setAll(Map<String,? extends Object> fields); final T save(); final boolean trySave(); final T insert(); final T create(); final void create(CreateCallback<T> callback); final void create(PostCreateCallback<T> callback); final boolean tryCreate(); final boolean tryCreate(CreateCallback<T> callback); final T upsert(); final T update(); final T update(UpdateCallback<T> callback); final T update(PostUpdateCallback<T> callback); final boolean tryUpdate(); final boolean tryUpdate(UpdateCallback<T> callback); final int updateAll(String whereExpression); final int updateAll(String whereExpression,Object... args); @SuppressWarnings("rawtypes") final int updateAll(String whereExpression,Map<String, Object> params); final void delete(); final boolean tryDelete(); final boolean load(); final boolean refresh(); final boolean validate(); final boolean validate(int maxErrors); final boolean validate(Iterable<String> fields); final boolean validate(int maxErrors, Iterable<String> fields); @Override void toJson(JsonWriter w); @Override String toString();  }
@Test public void testCompositeIdModelSet() { ModelWithCompositeId mc = new ModelWithCompositeId(); mc.set("id", "123"); assertEquals("123", mc.getId()); ModelWithId3 m3 = new ModelWithId3(); m3.set("id", New.hashMap("id1", "test1", "id2", "test2")); assertEquals("test1", m3.getId1()); assertEquals("test2", m3.getId2()); }