Codota Logo
ClassMetadata.hasIdentifierProperty
Code IndexAdd Codota to your IDE (free)

How to use
hasIdentifierProperty
method
in
org.hibernate.metadata.ClassMetadata

Best Java code snippets using org.hibernate.metadata.ClassMetadata.hasIdentifierProperty (Showing top 7 results out of 315)

  • Common ways to obtain ClassMetadata
private void myMethod () {
ClassMetadata c =
  • Codota IconSessionFactory sessionFactory;Class entityClass;sessionFactory.getClassMetadata(entityClass)
  • Codota IconSessionFactory sessionFactory;String entityName;sessionFactory.getClassMetadata(entityName)
  • Codota IconSessionFactory sessionFactory;Object object;sessionFactory.getClassMetadata(object.getClass())
  • Smart code suggestions by Codota
}
origin: com.atlassian.hibernate/hibernate.adapter

@Override
public boolean hasIdentifierProperty() {
  return metadata.hasIdentifierProperty();
}
origin: micromata/projectforge

 /**
  * @param obj1
  * @param obj2
  * @param sf
  * @return
  */
 private static boolean areEntitiesEqual(Object obj1, Object obj2, SessionFactory sf)
 {
  try {
   // compare the database identifier
   ClassMetadata clazz = sf.getClassMetadata(obj1.getClass());
   if (clazz != null) {
    if (clazz.hasIdentifierProperty() == true) {
     if (clazz.getIdentifier(obj1/* , EntityMode.POJO */)
       .equals(clazz.getIdentifier(obj2/* , EntityMode.POJO */)) == true) {
      return true;
     }
    }
   }
  } catch (Exception ex) {
   log.error("Exception occured:" + ex, ex);
  }

  return obj1.equals(obj2);
 }
}
origin: org.sakaiproject.genericdao/generic-dao

/**
* Use hibernate metadata to get the id value
*/
protected Serializable baseGetIdValue(Object object) {
 Class<?> type = findClass(object);
 Serializable idValue = null;
 ClassMetadata classmeta = getSessionFactory().getClassMetadata(type);
 if (classmeta != null) {
   if (classmeta.hasIdentifierProperty()) {
    idValue = classmeta.getIdentifier(object);
   }
 } else {
   throw new IllegalArgumentException("Could not get classmetadata for this object, it may not be persistent: " + object);
 }
 return idValue;
}
origin: hibernate/hibernate

/**
 * @param entity an actual entity object, not a proxy!
 */
public String toString(Object entity, EntityMode entityMode) throws HibernateException {
  // todo : this call will not work for anything other than pojos!
  ClassMetadata cm = factory.getClassMetadata( entity.getClass() );
  if ( cm==null ) return entity.getClass().getName();
  Map result = new HashMap();
  if ( cm.hasIdentifierProperty() ) {
    result.put(
      cm.getIdentifierPropertyName(),
      cm.getIdentifierType().toLoggableString( cm.getIdentifier( entity, entityMode ), factory )
    );
  }
  Type[] types = cm.getPropertyTypes();
  String[] names = cm.getPropertyNames();
  Object[] values = cm.getPropertyValues( entity, entityMode );
  for ( int i=0; i<types.length; i++ ) {
    if ( !names[i].startsWith("_") ) {
      String strValue = values[i]==LazyPropertyInitializer.UNFETCHED_PROPERTY ?
        values[i].toString() :
        types[i].toLoggableString( values[i], factory );
      result.put( names[i], strValue );
    }
  }
  return cm.getEntityName() + result.toString();
}
origin: jboss.jboss-embeddable-ejb3/hibernate-all

/**
 * @param entity an actual entity object, not a proxy!
 */
public String toString(Object entity, EntityMode entityMode) throws HibernateException {
  // todo : this call will not work for anything other than pojos!
  ClassMetadata cm = factory.getClassMetadata( entity.getClass() );
  if ( cm==null ) return entity.getClass().getName();
  Map result = new HashMap();
  if ( cm.hasIdentifierProperty() ) {
    result.put(
      cm.getIdentifierPropertyName(),
      cm.getIdentifierType().toLoggableString( cm.getIdentifier( entity, entityMode ), factory )
    );
  }
  Type[] types = cm.getPropertyTypes();
  String[] names = cm.getPropertyNames();
  Object[] values = cm.getPropertyValues( entity, entityMode );
  for ( int i=0; i<types.length; i++ ) {
    if ( !names[i].startsWith("_") ) {
      String strValue = values[i]==LazyPropertyInitializer.UNFETCHED_PROPERTY ?
        values[i].toString() :
        types[i].toLoggableString( values[i], factory );
      result.put( names[i], strValue );
    }
  }
  return cm.getEntityName() + result.toString();
}
origin: com.arsframework/ars-database

/**
 * 获取模型属性类型
 *
 * @param sessionFactory 会话工厂
 * @param model          数据模型
 * @param property       属性名称
 * @return 类型对象
 */
public static Type getPropertyType(SessionFactory sessionFactory, Class<?> model, String property) {
  int index = property.indexOf('.');
  if (index > 0) {
    Type type = getPropertyType(sessionFactory, model, property.substring(0, index));
    return getPropertyType(sessionFactory, getPropertyTypeClass(sessionFactory, type),
      property.substring(index + 1));
  }
  ClassMetadata metadata = getClassMetadata(sessionFactory, model);
  if (metadata.hasIdentifierProperty() && metadata.getIdentifierPropertyName().equals(property)) {
    return metadata.getIdentifierType();
  }
  return metadata.getPropertyType(property);
}
origin: com.github.mg365/mg-common

/**
 * 根据实体类创建元数据
 * @param entityClazz
 */
@Transactional
public boolean createMObjectFromEntityClass(Class entityClazz){
  Session factorySession = (org.hibernate.Session) entityManager.getDelegate();
  SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) factorySession.getSessionFactory();
  ClassMetadata entityMetaInfo = sessionFactory.getClassMetadata(entityClazz);
  String[] propertyNames = entityMetaInfo.getPropertyNames();
  for (int i = 0, n = propertyNames.length; i < n; i++)
  {
    String propertyName = propertyNames[i];
    Type propType = entityMetaInfo.getPropertyType(propertyName);//propType.sqlTypes(idPropType);;
    System.out.println(propertyName + "字段类型为" + propType.getReturnedClass().getName());
  }
  if (entityMetaInfo.hasIdentifierProperty()){
    String idPropName = entityMetaInfo.getIdentifierPropertyName();
    Type idPropType = entityMetaInfo.getIdentifierType();
    System.out.println("主键字段为:" + idPropName + "类型为"
        + idPropType.getReturnedClass().getName());
  } else {
    System.out.println("此实体无主键");
  }
  return true;
}
org.hibernate.metadataClassMetadatahasIdentifierProperty

Javadoc

Does this class have an identifier property?

Popular methods of ClassMetadata

  • getIdentifierPropertyName
    Get the name of the identifier property (or return null)
  • getIdentifierType
    Get the identifier Hibernate type
  • getEntityName
    The name of the entity
  • getPropertyNames
    Get the names of the class' persistent properties
  • getMappedClass
    The persistent class, or null
  • getIdentifier
  • getPropertyType
    Get the type of a particular (named) property
  • getPropertyTypes
    Get the Hibernate types of the class properties
  • getPropertyValue
    Get the value of a particular (named) property
  • getPropertyValues
    Extract the property values from the given entity.
  • setPropertyValue
    Set the value of a particular (named) property
  • instantiate
  • setPropertyValue,
  • instantiate,
  • getVersionProperty,
  • setIdentifier,
  • getPropertyNullability,
  • getVersion,
  • isVersioned,
  • getNaturalIdentifierProperties,
  • getPropertyLaziness

Popular in Java

  • Reactive rest calls using spring rest template
  • runOnUiThread (Activity)
  • findViewById (Activity)
  • getContentResolver (Context)
  • ObjectMapper (com.fasterxml.jackson.databind)
    This mapper (or, data binder, or codec) provides functionality for converting between Java objects (
  • NumberFormat (java.text)
    The abstract base class for all number formats. This class provides the interface for formatting and
  • GregorianCalendar (java.util)
    GregorianCalendar is a concrete subclass of Calendarand provides the standard calendar used by most
  • LinkedList (java.util)
    Doubly-linked list implementation of the List and Dequeinterfaces. Implements all optional list oper
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • JButton (javax.swing)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now