Package javax.persistence

Examples of javax.persistence.Id


  }

  private Field getIdField(Class<?> clazz) {
   Field idField = null;
   Field[] fields = clazz.getDeclaredFields();
   Id idAnnotation = null;
   for(Field field : fields) {
     idAnnotation = field.getAnnotation(Id.class);
     if(idAnnotation != null) {
       idField = field;
       break;
View Full Code Here


public class JavaxPersistenceImpl implements JavaxPersistenceConfigurer {

  public DatabaseFieldConfig createFieldConfig(DatabaseType databaseType, Field field) {
    Column columnAnnotation = field.getAnnotation(Column.class);
    Basic basicAnnotation = field.getAnnotation(Basic.class);
    Id idAnnotation = field.getAnnotation(Id.class);
    GeneratedValue generatedValueAnnotation = field.getAnnotation(GeneratedValue.class);
    OneToOne oneToOneAnnotation = field.getAnnotation(OneToOne.class);
    ManyToOne manyToOneAnnotation = field.getAnnotation(ManyToOne.class);
    JoinColumn joinColumnAnnotation = field.getAnnotation(JoinColumn.class);
    Enumerated enumeratedAnnotation = field.getAnnotation(Enumerated.class);
View Full Code Here

  public void save(T entity){
    try {
      // 获取实体编号
      Object id = null;
      for (Method method : entity.getClass().getMethods()){
        Id idAnn = method.getAnnotation(Id.class);
        if (idAnn != null){
          id = method.invoke(entity);
          break;
        }
      }
View Full Code Here

        Field[] declaredFields = clazz.getDeclaredFields();
        FieldMapper tempIdMapper = null;
        CompositeColumnEntityMapper tempEmbeddedEntityMapper = null;
        for (Field field : declaredFields) {
            // Should only have one id field and it should map to the row key
            Id idAnnotation = field.getAnnotation(Id.class);
            if(idAnnotation != null) {
                Preconditions.checkArgument(tempIdMapper == null, "there are multiple fields with @Id annotation");
                field.setAccessible(true);
                tempIdMapper = new FieldMapper(field, prefix);
            }
View Full Code Here

    columnList = Maps.newHashMapWithExpectedSize(declaredFields.length);
    Set<String> usedColumnNames = Sets.newHashSet();
    Field tmpIdField = null;
    ColumnMapper tempUniqueMapper = null;
    for (Field field : declaredFields) {
      Id idAnnotation = field.getAnnotation(Id.class);
      if(idAnnotation != null) {
        Preconditions.checkArgument(tmpIdField == null, "there are multiple fields with @Id annotation");
        field.setAccessible(true);
        tmpIdField = field;
      }
View Full Code Here

        try{
            do {
                Field[] fields = varClass.getDeclaredFields();
                for (int i = 0; i < fields.length && idValue == null; i++) {
                    Field field = fields[i];
                    Id id = field.getAnnotation(Id.class);
                    if (id != null) {
                        try {
                            idValue = callIdMethod(o, "get"
                                    + Character.toUpperCase(field.getName().charAt(0))
                                    + field.getName().substring(1));
                        } catch (NoSuchMethodException e) {
                            idValue = (Serializable) field.get(o);
                        }
                    }
                }
            } while ((varClass = varClass.getSuperclass()) != null && idValue == null);
            if (idValue == null) {
                varClass = o.getClass();
                do {
                    Method[] methods = varClass.getMethods();
                    for (int i = 0; i < methods.length && idValue == null; i++) {
                        Method method = methods[i];
                        Id id = method.getAnnotation(Id.class);
                        if (id != null) {
                            idValue = (Serializable) method.invoke(o);
                        }
                    }
                } while ((varClass = varClass.getSuperclass()) != null && idValue == null);
View Full Code Here

        Class<? extends Object> varClass = o.getClass();
        do {
                Field[] fields = varClass.getDeclaredFields();
                for (int i = 0; i < fields.length; i++) {
                    Field field = fields[i];
                    Id id = field.getAnnotation(Id.class);
                    if (id != null) {
                       return true;
                    }
                }
        } while ((varClass = varClass.getSuperclass()) != null);
        varClass = o.getClass();
        do {
                    Method[] methods = varClass.getMethods();
                    for (int i = 0; i < methods.length; i++) {
                        Method method = methods[i];
                        Id id = method.getAnnotation(Id.class);
                        if (id != null) {
                            return true;
                        }
                    }
        } while ((varClass = varClass.getSuperclass()) != null );
View Full Code Here

TOP

Related Classes of javax.persistence.Id

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.