Package javax.persistence

Examples of javax.persistence.Id


        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

  private Method getIdMethod(Class< ? > clazz) {
    Method idMethod = null;
    // Get all public declared methods on the class. According to spec, @Id should only be
    // applied to fields and property get methods
    Method[] methods = clazz.getMethods();
    Id idAnnotation = null;
    for(Method method : methods) {
      idAnnotation = method.getAnnotation(Id.class);
      if(idAnnotation != null) {
        idMethod = method;
        break;
View Full Code Here

  }

  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

    }
    else {
      Column col = getAnnotation(objectType, parameterName, Column.class);
      if (col != null)
        sn = col.name();
      Id id = getAnnotation(objectType, parameterName, Id.class);
      Version version = getAnnotation(objectType, parameterName, Version.class);
      GeneratedValue generated = getAnnotation(objectType, parameterName, GeneratedValue.class);
     
      boolean idFlag = id != null;
      boolean versionFlag = version != null;
View Full Code Here

      SecurityException, IllegalAccessException,
      InvocationTargetException, IllegalArgumentException {
    Field[] fields = o.getClass().getDeclaredFields();
    Long idValue = null;
    for (int i = 0; i < fields.length; i++) {
      Id id = fields[i].getAnnotation(Id.class);
      if (id != null) {
        idValue = (Long) o.getClass().getMethod("get"
          + Character.toUpperCase(fields[i].getName().charAt(0))
          + fields[i].getName().substring(1),
          new Class<?>[] {}).invoke(o, new Object[] {});
View Full Code Here

  }

  public static void setAutoId(Object o) {
    Class<?> cls = o.getClass();
    for (Field f : cls.getDeclaredFields()) {
      Id id = f.getAnnotation(Id.class);
      if (id == null)
        continue;

      String capName = StringUtils.capitalize(f.getName());
      String getterName = "get" + capName;
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

  private Method getIdMethod(Class< ? > clazz) {
    Method idMethod = null;
    // Get all public declared methods on the class. According to spec, @Id should only be
    // applied to fields and property get methods
    Method[] methods = clazz.getMethods();
    Id idAnnotation = null;
    for(Method method : methods) {
      idAnnotation = method.getAnnotation(Id.class);
      if(idAnnotation != null) {
        idMethod = method;
        break;
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.