Example usage for org.hibernate SessionFactory getClassMetadata

List of usage examples for org.hibernate SessionFactory getClassMetadata

Introduction

In this page you can find the example usage for org.hibernate SessionFactory getClassMetadata.

Prototype

@Deprecated
ClassMetadata getClassMetadata(String entityName);

Source Link

Document

Retrieve the ClassMetadata associated with the given entity class.

Usage

From source file:org.riotfamily.common.hibernate.HibernateUtils.java

License:Apache License

public static Serializable getId(SessionFactory sessionFactory, Object bean) {
    Class<?> clazz = Hibernate.getClass(bean);
    ClassMetadata metadata = sessionFactory.getClassMetadata(clazz);
    return metadata.getIdentifier(bean, EntityMode.POJO);
}

From source file:org.riotfamily.common.hibernate.HibernateUtils.java

License:Apache License

public static boolean isPersistentProperty(SessionFactory sessionFactory, Class<?> clazz, String propertyPath) {

    int pos = PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(propertyPath);
    // Handle nested properties recursively.
    if (pos > -1) {
        String nestedProperty = propertyPath.substring(0, pos);
        String nestedPath = propertyPath.substring(pos + 1);
        Class<?> nestedClazz = PropertyUtils.getPropertyType(clazz, nestedProperty);
        return isPersistentProperty(sessionFactory, clazz, nestedProperty)
                && isPersistentProperty(sessionFactory, nestedClazz, nestedPath);
    } else {//from  w  w w.  j  a  v  a  2 s .co m
        try {
            ClassMetadata metadata = sessionFactory.getClassMetadata(clazz);
            if (metadata == null) {
                return false;
            }
            return metadata.getPropertyType(propertyPath) != null;
        } catch (HibernateException e) {
            return false;
        }
    }
}

From source file:org.seasar.hibernate.jpa.PersistenceUnitConfigurationTest.java

License:Apache License

public void testReadPersistenceXmlFile() throws Exception {
    final Session session = Session.class.cast(em.getDelegate());
    final SessionFactory sf = session.getSessionFactory();
    assertEquals(2, sf.getAllClassMetadata().size());
    assertNotNull(sf.getClassMetadata(Employee.class));
    assertNotNull(sf.getClassMetadata(Department.class));
}

From source file:org.seasar.hibernate.jpa.PersistenceUnitConfigurationTest.java

License:Apache License

public void testAddMappingFile() throws Exception {
    final Session session = Session.class.cast(em.getDelegate());
    final SessionFactory sf = session.getSessionFactory();
    assertEquals(3, sf.getAllClassMetadata().size());
    assertNotNull(sf.getClassMetadata(Employee.class));
    assertNotNull(sf.getClassMetadata(Department.class));
    assertNotNull(sf.getClassMetadata(Employee2.class));
}

From source file:org.seasar.hibernate.jpa.PersistenceUnitConfigurationTest.java

License:Apache License

public void testAddPersistenceClass() throws Exception {
    final Session session = Session.class.cast(em.getDelegate());
    final SessionFactory sf = session.getSessionFactory();
    assertEquals(3, sf.getAllClassMetadata().size());
    assertNotNull(sf.getClassMetadata(Employee.class));
    assertNotNull(sf.getClassMetadata(Department.class));
    assertNotNull(sf.getClassMetadata(Department2.class));
}

From source file:org.seasar.hibernate.jpa.PersistenceUnitConfigurationTest.java

License:Apache License

public void testMappingFileAutoDetection() throws Exception {
    final Session session = Session.class.cast(em.getDelegate());
    final SessionFactory sf = session.getSessionFactory();
    assertEquals(5, sf.getAllClassMetadata().size());
    assertNotNull(sf.getClassMetadata(Employee.class));
    assertNotNull(sf.getClassMetadata(Department.class));
    assertNotNull(sf.getClassMetadata(Employee2.class));
    assertNotNull(sf.getClassMetadata(Address.class));
    assertNotNull(sf.getClassMetadata(Project.class));
}

From source file:org.seasar.hibernate.jpa.PersistenceUnitConfigurationTest.java

License:Apache License

public void testMappingFileAutoDetectionSubPackage() throws Exception {
    final PersistenceUnitManager pum = PersistenceUnitManager.class
            .cast(getComponent(PersistenceUnitManager.class));
    final EntityManagerFactory emf = pum.getEntityManagerFactory("aaaPersistenceUnit");
    final EntityManager em = emf.createEntityManager();
    final Session session = Session.class.cast(em.getDelegate());
    final SessionFactory sf = session.getSessionFactory();
    assertEquals(3, sf.getAllClassMetadata().size());
    assertNotNull(sf.getClassMetadata(Dummy2.class));
}

From source file:org.seasar.hibernate.jpa.PersistenceUnitConfigurationTest.java

License:Apache License

public void testPersistenceClassAutoDetection() throws Exception {
    final Session session = Session.class.cast(em.getDelegate());
    final SessionFactory sf = session.getSessionFactory();
    assertEquals(4, sf.getAllClassMetadata().size());
    assertNotNull(sf.getClassMetadata(Employee.class));
    assertNotNull(sf.getClassMetadata(Department.class));
    assertNotNull(sf.getClassMetadata(Customer.class));
    assertNotNull(sf.getClassMetadata(Department2.class));
}

From source file:org.seasar.hibernate.jpa.PersistenceUnitConfigurationTest.java

License:Apache License

public void testPersistenceClassAutoDetectionSubPackage() throws Exception {
    final PersistenceUnitManager pum = PersistenceUnitManager.class
            .cast(getComponent(PersistenceUnitManager.class));
    final EntityManagerFactory emf = pum.getEntityManagerFactory("aaaPersistenceUnit");
    final EntityManager em = emf.createEntityManager();
    final Session session = Session.class.cast(em.getDelegate());
    final SessionFactory sf = session.getSessionFactory();
    assertEquals(3, sf.getAllClassMetadata().size());
    assertNotNull(sf.getClassMetadata(Dummy.class));
}

From source file:org.shept.persistence.provider.DaoUtils.java

License:Apache License

private static ClassMetadata getClassMetadata(DaoSupport dao, Object model) {
    checkProvider(dao);//from  w  w w .  ja  va2s. c om
    SessionFactory hsf = ((HibernateDaoSupport) dao).getHibernateTemplate().getSessionFactory();
    if (model == null) {
        return null;
    }
    return hsf.getClassMetadata(model.getClass());
}