Package org.hibernate.metadata

Examples of org.hibernate.metadata.ClassMetadata


      return PersistenceUtilHelper.isLoaded( entity ) != LoadState.NOT_LOADED;
    }

    public Object getIdentifier(Object entity) {
      final Class entityClass = Hibernate.getClass( entity );
      final ClassMetadata classMetadata = emf.getSessionFactory().getClassMetadata( entityClass );
      if (classMetadata == null) {
        throw new IllegalArgumentException( entityClass + " is not an entity" );
      }
      //TODO does that work for @IdClass?
      return classMetadata.getIdentifier( entity );
    }
View Full Code Here


  public boolean matches(Class valueClass) {
    boolean matches = false;
    JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
    if (jbpmContext!=null) {
      SessionFactory sessionFactory = jbpmContext.getSessionFactory();
      ClassMetadata classMetadata = sessionFactory.getClassMetadata(valueClass);
      matches = ( (classMetadata!=null)
                  && (classMetadata.getIdentifierType().getClass()==StringType.class)
                 );
    } else {
      log.debug("no current context so valueClass cannot be stored as a string-id-ref to a hibernate object");
      matches = false;
    }
View Full Code Here

  public boolean matches(Class valueClass) {
    boolean matches = false;
    JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
    if (jbpmContext!=null) {
      SessionFactory sessionFactory = jbpmContext.getSessionFactory();
      ClassMetadata classMetadata = sessionFactory.getClassMetadata(valueClass);
      matches =  ( (classMetadata!=null)
                   && (classMetadata.getIdentifierType().getClass()==LongType.class)
                 );
    } else {
      log.debug("no current context so valueClass cannot be stored as a long-id-ref to a hibernate object");
      matches = false;
    }
View Full Code Here

        Session session = source.create();
        assertNotNull(session);

        // make sure it found the entity in the package
        ClassMetadata meta = session.getSessionFactory().getClassMetadata(User.class);
        assertEquals(meta.getEntityName(), "org.example.app0.entities.User");

        verify();
    }
View Full Code Here

*/
@SuppressWarnings("unchecked")
public class NaturalIdTest extends TestCase {

  public void testMappingProperties() {
    ClassMetadata metaData = getSessions().getClassMetadata(
        Citizen.class
    );
    assertTrue(
        "Class should have a natural key", metaData
            .hasNaturalIdentifier()
    );
    int[] propertiesIndex = metaData.getNaturalIdentifierProperties();
    assertTrue( "Wrong number of elements", propertiesIndex.length == 2 );
  }
View Full Code Here

  private Logger log = LoggerFactory.getLogger( NaturalIdOnManyToOne.class );

  public void testMappingProperties() {
    log.warn( "Commented out test" );

    ClassMetadata metaData = getSessions().getClassMetadata(
        NaturalIdOnManyToOne.class
    );
    assertTrue(
        "Class should have a natural key", metaData
            .hasNaturalIdentifier()
    );
    int[] propertiesIndex = metaData.getNaturalIdentifierProperties();
    assertTrue( "Wrong number of elements", propertiesIndex.length == 1 );
  }
View Full Code Here

    assertTimestampSource( DBTimestamped.class, DbTimestampType.class );
  }

  private void assertTimestampSource(Class<?> clazz, Class<?> expectedTypeClass) throws Exception {
    buildConfiguration();
    ClassMetadata meta = sessions.getClassMetadata( clazz );
    assertTrue( "Entity is annotated with @Timestamp and should hence be versioned", meta.isVersioned() );

    PersistentClass persistentClass = cfg.getClassMapping( clazz.getName() );
    assertNotNull( persistentClass );
    Property versionProperty = persistentClass.getVersion();
    assertNotNull( versionProperty );
View Full Code Here

        Integer result = 0;
       
        try {
           
            SessionFactory sessionFactory = ht.getSessionFactory();
            ClassMetadata meta = sessionFactory.getClassMetadata(getPersistentClass());
           
            String[] propertyNames = meta.getPropertyNames();
            Type[] propertyTypes = meta.getPropertyTypes();
            Object[] propertyValues = meta.getPropertyValues(entity, EntityMode.POJO);
           
            Integer id = entity.getId();
            ReflectionUtils.invokeMethod(new PropertyDescriptor(meta.getIdentifierPropertyName(), getPersistentClass()).getWriteMethod(), entity, new Object[] {null});
             
            DetachedCriteria criteria = DetachedCriteria.forClass(getPersistentClass());
             
            if (id != null) {
                criteria.add(Restrictions.not(Restrictions.eq(meta.getIdentifierPropertyName(), id)));
            }
           
            for ( int i=0; i<propertyNames.length; i++ ) {
                String name = propertyNames[i];
                Type type = propertyTypes[i];
View Full Code Here

     */
    private DetachedCriteria mountCriteriaForFindByAttributes(T entity, final String sortField, final Boolean sortOrder) {
        DetachedCriteria criteria = DetachedCriteria.forClass(getPersistentClass());

        SessionFactory sessionFactory = ht.getSessionFactory();
        ClassMetadata meta = sessionFactory.getClassMetadata(getPersistentClass());

        String[] propertyNames = meta.getPropertyNames();
        Type[] propertyTypes = meta.getPropertyTypes();
        Object[] propertyValues = meta.getPropertyValues(entity, EntityMode.POJO);

        /*
         * Adicionando o atributo identificador único(id) caso o mesmo tenha
         * sido informado e exista um atributo chave.
         */
        if (entity.getId() != null  &&  meta.getIdentifierPropertyName()!=null) {
            criteria.add(Restrictions.eq(meta.getIdentifierPropertyName(), entity.getId()));
        }

        /*
         * Varrendo todos os atributos da entidade. Como na listagem não consta
         * o atributo identificador único(id), este foi observado na rotina anterior.
View Full Code Here

    public Integer countByAttributesExceptMySelf(T entity) {
       
      Integer result = 0;

        try {
          ClassMetadata meta = getClassMetadata();
          Integer id = entity.getId();
          ReflectionUtils.invokeMethod(new PropertyDescriptor(meta.getIdentifierPropertyName(), getPersistentClass()).getWriteMethod(), entity, new Object[] {null});
           
          DetachedCriteria criteria = mountCriteriaForFindByAttributes(entity, null, null);
           
          if (id != null) {
              criteria.add(Restrictions.not(Restrictions.eq(meta.getIdentifierPropertyName(), id)));
          }
         
          result = countByCriteria(criteria);
         
        } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.hibernate.metadata.ClassMetadata

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.