@Test public void testGetMetadataFromFields_EntityClass() { EntityClassMetadata<Person_F> metadata = factory .getEntityClassMetadata(Person_F.class); assertEquals("Person_F", metadata.getEntityName()); assertEquals(Person_F.class, metadata.getMappedClass()); assertTrue(metadata.hasIdentifierProperty()); { PersistentPropertyMetadata id = metadata.getIdentifierProperty(); assertEquals("id", id.getName()); assertEquals(Integer.class, id.getType()); assertEquals(PersistentPropertyMetadata.AccessType.FIELD, id.getAccessType()); assertNotNull(id.getAnnotation(Id.class)); assertNull(id.getTypeMetadata()); assertTrue(id.isWritable()); } assertTrue(metadata.hasVersionProperty()); { PersistentPropertyMetadata version = metadata.getVersionProperty(); assertEquals("version", version.getName()); assertEquals(Integer.class, version.getType()); assertEquals(PersistentPropertyMetadata.AccessType.FIELD, version.getAccessType()); assertNotNull(version.getAnnotation(Version.class)); assertNull(version.getTypeMetadata()); assertTrue(version.isWritable()); } assertFalse(metadata.hasEmbeddedIdentifier()); assertSame(metadata.getIdentifierProperty(), metadata.getProperty("id")); assertSame(metadata.getVersionProperty(), metadata.getProperty("version")); { PersistentPropertyMetadata prop = (PersistentPropertyMetadata) metadata .getProperty("firstName"); assertEquals("firstName", prop.getName()); assertEquals(String.class, prop.getType()); assertEquals(PersistentPropertyMetadata.AccessType.FIELD, prop.getAccessType()); assertEquals(PropertyKind.SIMPLE, prop.getPropertyKind()); assertNull(prop.getTypeMetadata()); assertTrue(prop.isWritable()); } { PersistentPropertyMetadata prop = (PersistentPropertyMetadata) metadata .getProperty("lastName"); assertEquals("lastName", prop.getName()); assertEquals(String.class, prop.getType()); assertEquals(PersistentPropertyMetadata.AccessType.FIELD, prop.getAccessType()); assertEquals(PropertyKind.SIMPLE, prop.getPropertyKind()); assertNull(prop.getTypeMetadata()); assertTrue(prop.isWritable()); } { PersistentPropertyMetadata prop = (PersistentPropertyMetadata) metadata .getProperty("address"); assertEquals("address", prop.getName()); assertEquals(Address_F.class, prop.getType()); assertEquals(PersistentPropertyMetadata.AccessType.FIELD, prop.getAccessType()); assertEquals(PropertyKind.EMBEDDED, prop.getPropertyKind()); assertNotNull(prop.getTypeMetadata()); assertTrue(prop.isWritable()); } { PersistentPropertyMetadata prop = (PersistentPropertyMetadata) metadata .getProperty("children"); assertEquals("children", prop.getName()); assertEquals(Collection.class, prop.getType()); assertEquals(PersistentPropertyMetadata.AccessType.FIELD, prop.getAccessType()); assertEquals(PropertyKind.ONE_TO_MANY, prop.getPropertyKind()); assertNull(prop.getTypeMetadata()); assertTrue(prop.isWritable()); } { PersistentPropertyMetadata prop = (PersistentPropertyMetadata) metadata .getProperty("parent"); assertEquals("parent", prop.getName()); assertEquals(Person_F.class, prop.getType()); assertEquals(PersistentPropertyMetadata.AccessType.FIELD, prop.getAccessType()); assertEquals(PropertyKind.MANY_TO_ONE, prop.getPropertyKind()); assertSame(metadata, prop.getTypeMetadata()); assertTrue(prop.isWritable()); } assertNull(metadata.getProperty("transientField")); assertNull(metadata.getProperty("transientField2")); { PropertyMetadata prop = metadata.getProperty("transientBaseField"); assertEquals("transientBaseField", prop.getName()); assertEquals(Integer.class, prop.getType()); assertFalse(prop.isWritable()); } { PropertyMetadata prop = metadata.getProperty("transientField3"); assertEquals("transientField3", prop.getName()); assertEquals(String.class, prop.getType()); assertFalse(prop.isWritable()); } { PropertyMetadata prop = metadata.getProperty("transientField4"); assertEquals("transientField4", prop.getName()); assertEquals(String.class, prop.getType()); assertTrue(prop.isWritable()); } { PropertyMetadata prop = metadata.getProperty("transientAddress"); assertEquals("transientAddress", prop.getName()); assertEquals(Address_M.class, prop.getType()); assertTrue(prop.isWritable()); } assertEquals(11, metadata.getProperties().size()); }
public <T> EntityClassMetadata<T> getEntityClassMetadata( Class<T> mappedClass) throws IllegalArgumentException { assert mappedClass != null : "mappedClass must not be null"; if (mappedClass.getAnnotation(Entity.class) == null) { throw new IllegalArgumentException("The class is not an entity"); } PersistentPropertyMetadata.AccessType accessType = determineAccessType(mappedClass); if (accessType == null) { throw new IllegalArgumentException( "The access type could not be determined"); } else { return (EntityClassMetadata<T>) getClassMetadata(mappedClass, accessType); } }
MetadataFactory { public <T> EntityClassMetadata<T> getEntityClassMetadata( Class<T> mappedClass) throws IllegalArgumentException { assert mappedClass != null : "mappedClass must not be null"; if (mappedClass.getAnnotation(Entity.class) == null) { throw new IllegalArgumentException("The class is not an entity"); } PersistentPropertyMetadata.AccessType accessType = determineAccessType(mappedClass); if (accessType == null) { throw new IllegalArgumentException( "The access type could not be determined"); } else { return (EntityClassMetadata<T>) getClassMetadata(mappedClass, accessType); } } }
MetadataFactory { public <T> EntityClassMetadata<T> getEntityClassMetadata( Class<T> mappedClass) throws IllegalArgumentException { assert mappedClass != null : "mappedClass must not be null"; if (mappedClass.getAnnotation(Entity.class) == null) { throw new IllegalArgumentException("The class is not an entity"); } PersistentPropertyMetadata.AccessType accessType = determineAccessType(mappedClass); if (accessType == null) { throw new IllegalArgumentException( "The access type could not be determined"); } else { return (EntityClassMetadata<T>) getClassMetadata(mappedClass, accessType); } } protected  MetadataFactory(); }
MetadataFactory { public <T> EntityClassMetadata<T> getEntityClassMetadata( Class<T> mappedClass) throws IllegalArgumentException { assert mappedClass != null : "mappedClass must not be null"; if (mappedClass.getAnnotation(Entity.class) == null) { throw new IllegalArgumentException("The class is not an entity"); } PersistentPropertyMetadata.AccessType accessType = determineAccessType(mappedClass); if (accessType == null) { throw new IllegalArgumentException( "The access type could not be determined"); } else { return (EntityClassMetadata<T>) getClassMetadata(mappedClass, accessType); } } protected  MetadataFactory(); static MetadataFactory getInstance(); EntityClassMetadata<T> getEntityClassMetadata(
            Class<T> mappedClass); @SuppressWarnings("unchecked") ClassMetadata<T> getClassMetadata(Class<T> mappedClass,
            PersistentPropertyMetadata.AccessType accessType); }
MetadataFactory { public <T> EntityClassMetadata<T> getEntityClassMetadata( Class<T> mappedClass) throws IllegalArgumentException { assert mappedClass != null : "mappedClass must not be null"; if (mappedClass.getAnnotation(Entity.class) == null) { throw new IllegalArgumentException("The class is not an entity"); } PersistentPropertyMetadata.AccessType accessType = determineAccessType(mappedClass); if (accessType == null) { throw new IllegalArgumentException( "The access type could not be determined"); } else { return (EntityClassMetadata<T>) getClassMetadata(mappedClass, accessType); } } protected  MetadataFactory(); static MetadataFactory getInstance(); EntityClassMetadata<T> getEntityClassMetadata(
            Class<T> mappedClass); @SuppressWarnings("unchecked") ClassMetadata<T> getClassMetadata(Class<T> mappedClass,
            PersistentPropertyMetadata.AccessType accessType);  }