Package javax.persistence

Examples of javax.persistence.ManyToOne


  }

  protected static void defineFetchingStrategy(ToOne toOne, XProperty property) {
    LazyToOne lazy = property.getAnnotation( LazyToOne.class );
    Fetch fetch = property.getAnnotation( Fetch.class );
    ManyToOne manyToOne = property.getAnnotation( ManyToOne.class );
    OneToOne oneToOne = property.getAnnotation( OneToOne.class );
    FetchType fetchType;
    if ( manyToOne != null ) {
      fetchType = manyToOne.fetch();
    }
    else if ( oneToOne != null ) {
      fetchType = oneToOne.fetch();
    }
    else {
View Full Code Here


        for (Map.Entry<Field, Annotations> entry : fields.entrySet()) {
            Field field = entry.getKey();
            Annotations annotations = entry.getValue();

            OneToOne oneToOne = annotations.get(OneToOne.class);
            ManyToOne manyToOne = annotations.get(ManyToOne.class);
            OneToMany oneToMany = annotations.get(OneToMany.class);
            ManyToMany manyToMany = annotations.get(ManyToMany.class);

            if (oneToOne != null) {
                analyzeOneToOne(n, field, annotations, oneToOne);
View Full Code Here

        int idx = 0;
        for (AnnotatedField f : pkFields) {
            columns[idx] = getColumnName(f);
            if (columns[idx] == null) {
                //check for the special case, @Id with @JoinColumn and @ManyToOne
                ManyToOne manyToOne = f.getAnnotation(ManyToOne.class);
                if (manyToOne == null) {
                    columns[idx] = f.getName().toUpperCase();
                } else {
                    JoinColumn joinColumn = f.getAnnotation(JoinColumn.class);
                    columns[idx] = joinColumn.name();
View Full Code Here

   * cascade settings.
   */
  public void testCascadeAllPlusMore() throws Exception {
    reader = getReader( Entity1.class, "field1", "many-to-one.orm9.xml" );
    assertAnnotationPresent( ManyToOne.class );
    ManyToOne relAnno = reader.getAnnotation( ManyToOne.class );
    assertEquals( 6, relAnno.cascade().length );
    assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
    assertEquals( CascadeType.PERSIST, relAnno.cascade()[1] );
    assertEquals( CascadeType.MERGE, relAnno.cascade()[2] );
    assertEquals( CascadeType.REMOVE, relAnno.cascade()[3] );
    assertEquals( CascadeType.REFRESH, relAnno.cascade()[4] );
    assertEquals( CascadeType.DETACH, relAnno.cascade()[5] );
  }
View Full Code Here

    assertAnnotationNotPresent( JoinColumns.class );
    assertAnnotationNotPresent( JoinTable.class );
    assertAnnotationPresent( Id.class );
    assertAnnotationPresent( MapsId.class );
    assertAnnotationPresent( Access.class );
    ManyToOne relAnno = reader.getAnnotation( ManyToOne.class );
    assertEquals( 0, relAnno.cascade().length );
    assertEquals( FetchType.LAZY, relAnno.fetch() );
    assertFalse( relAnno.optional() );
    assertEquals( Entity3.class, relAnno.targetEntity() );
    assertEquals( "col1", reader.getAnnotation( MapsId.class ).value() );
    assertEquals(
        AccessType.PROPERTY, reader.getAnnotation( Access.class )
        .value()
    );
View Full Code Here

  }

  public void testCascadeAll() throws Exception {
    reader = getReader( Entity1.class, "field1", "many-to-one.orm7.xml" );
    assertAnnotationPresent( ManyToOne.class );
    ManyToOne relAnno = reader.getAnnotation( ManyToOne.class );
    assertEquals( 1, relAnno.cascade().length );
    assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
  }
View Full Code Here

  }

  public void testCascadeSomeWithDefaultPersist() throws Exception {
    reader = getReader( Entity1.class, "field1", "many-to-one.orm8.xml" );
    assertAnnotationPresent( ManyToOne.class );
    ManyToOne relAnno = reader.getAnnotation( ManyToOne.class );
    assertEquals( 4, relAnno.cascade().length );
    assertEquals( CascadeType.REMOVE, relAnno.cascade()[0] );
    assertEquals( CascadeType.REFRESH, relAnno.cascade()[1] );
    assertEquals( CascadeType.DETACH, relAnno.cascade()[2] );
    assertEquals( CascadeType.PERSIST, relAnno.cascade()[3] );
  }
View Full Code Here

            messages.add("check M-1 "+relationship.getName()+": Wrong type of Collection");
            return false;
        }
        */
       
        ManyToOne annotation = (ManyToOne)method.getAnnotation(ManyToOne.class);
        Class targetEntity = annotation.targetEntity();

        if (targetEntity.getName().equals("void"))
        {
           
            messages.add("check M-1 "+relationship.getName()+": Missing Target Entity");
View Full Code Here

        }

        if (annotations[k].annotationType().equals(javax.persistence.ManyToOne.class))
        {
          ManyToOne a = (ManyToOne) annotations[k];

          if (a.targetEntity().equals(""))
            throw new MissingTargetEntityException(beanName, methods[j].getName());

          rel = new Relationship(beanName);
          rel.setName(methods[j].getName());

          rel.setFromMany(true);
          rel.setToMany(false);
          rel.setToBeanClassName(a.targetEntity().getCanonicalName());
        }

        if (annotations[k].annotationType().equals(javax.persistence.ManyToMany.class))
        {
          ManyToMany a = (ManyToMany) annotations[k];

          if (a.targetEntity().equals(""))
            throw new MissingTargetEntityException(beanName, methods[j].getName());

          rel = new Relationship(beanName);
          rel.setName(methods[j].getName());

          rel.setFromMany(true);
          rel.setToMany(true);
          rel.setToBeanClassName(a.targetEntity().getCanonicalName());
          rel.setMappedBy(a.mappedBy());
        }

        if (annotations[k].annotationType().equals(javax.persistence.OneToOne.class))
        {
          OneToOne a = (OneToOne) annotations[k];

          if (a.targetEntity().equals(""))
            throw new MissingTargetEntityException(beanName, methods[j].getName());

          rel = new Relationship(beanName);
          rel.setName(methods[j].getName());

          rel.setFromMany(false);
          rel.setToMany(false);
          rel.setToBeanClassName(a.targetEntity().getCanonicalName());
          rel.setMappedBy(a.mappedBy());
        }

        /**
         * Annotazioni relative alla generazione !!!!
         *
 
View Full Code Here

          rel.setMappedBy(a.mappedBy());
        }

        if (annotations[k].annotationType().equals(javax.persistence.ManyToOne.class))
        {
          ManyToOne a = (ManyToOne) annotations[k];

          if (a.targetEntity().equals(""))
            throw new MissingTargetEntityException(beanName, methods[j].getName());

          rel = new Relationship(beanName);
          rel.setName(methods[j].getName());

          rel.setFromMany(true);
          rel.setToMany(false);
          rel.setToBeanClassName(a.targetEntity().getCanonicalName());
        }

        if (annotations[k].annotationType().equals(javax.persistence.ManyToMany.class))
        {
          ManyToMany a = (ManyToMany) annotations[k];

          if (a.targetEntity().equals(""))
            throw new MissingTargetEntityException(beanName, methods[j].getName());

          rel = new Relationship(beanName);
          rel.setName(methods[j].getName());

          rel.setFromMany(true);
          rel.setToMany(true);
          rel.setToBeanClassName(a.targetEntity().getCanonicalName());
          rel.setMappedBy(a.mappedBy());
        }

        if (annotations[k].annotationType().equals(javax.persistence.OneToOne.class))
        {
          OneToOne a = (OneToOne) annotations[k];

          if (a.targetEntity().equals(""))
            throw new MissingTargetEntityException(beanName, methods[j].getName());

          rel = new Relationship(beanName);
          rel.setName(methods[j].getName());

          rel.setFromMany(false);
          rel.setToMany(false);
          rel.setToBeanClassName(a.targetEntity().getCanonicalName());
          rel.setMappedBy(a.mappedBy());
        }
      }

      if (rel != null)
        tmp.add(rel);
View Full Code Here

TOP

Related Classes of javax.persistence.ManyToOne

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.