congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
ClassMetadata.hasIdentifierProperty
Code IndexAdd Tabnine 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)

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
  • addToBackStack (FragmentTransaction)
  • getContentResolver (Context)
  • putExtra (Intent)
  • String (java.lang)
  • Hashtable (java.util)
    A plug-in replacement for JDK1.5 java.util.Hashtable. This version is based on org.cliffc.high_scale
  • TreeMap (java.util)
    Walk the nodes of the tree left-to-right or right-to-left. Note that in descending iterations, next
  • Annotation (javassist.bytecode.annotation)
    The annotation structure.An instance of this class is returned bygetAnnotations() in AnnotationsAttr
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • JButton (javax.swing)
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now