public int insert() throws ActiveRecordException {
		Connection conn = DbKit.getConnection();
		TransactionManager tx = new TransactionManager(conn);
		//开启事务
		tx.begainTransaction();
		DaoSupport dao = new DaoSupport(conn);
		OrmInfo orm;
		int update = 0;
		try {
			orm = OrmInfo.getOrmInfo(this);
			update  = dao.insert(orm);
			//取得刚插入行的id
			this.keyId = dao.getKeyId();
			if(/*0 != update &&*/ -1 != getKeyId()){
				//处理一对多关系的插入
				for (Entry<String, OneToManyField> entry : orm.getOTMFields()	.entrySet()) {
					//String fieldName = entry.getKey();
					List<?> values = (List<?>) orm.getFieldValue(entry.getValue().getField(), this);
					if(null != values){
						for (Object obj : values) {							
							ActiveRecordBase ar = (ActiveRecordBase) obj;
							Field f = obj.getClass().getDeclaredField(entry.getValue().getForeignKey());
							orm.setFieldValue(f, obj, getKeyId());
							ar.insert();
						}
					}
				}
				//处理一对一关系的插入
				for(Entry<String, OneToOneField> entry : orm.getOTOFields().entrySet()){
					//String fieldName = entry.getKey();
					Object obj = orm.getFieldValue(entry.getValue().getField(), this);
					if(null != obj){
						Field f= obj.getClass().getDeclaredField(entry.getValue().getForeignKey());
						orm.setFieldValue(f, obj, getKeyId());
						ActiveRecordBase ar = (ActiveRecordBase) obj;
						ar.insert();
					}
					
				}
			}
			
		} catch (Exception e) {
			tx.rollbackTransaction();
			throw new ActiveRecordException(e);
		}

		tx.commitTransaction();
		return update; 		
	}