List of usage examples for org.hibernate.metadata ClassMetadata hasNaturalIdentifier
boolean hasNaturalIdentifier();
From source file:cz.jirutka.commons.hibernate.HibernateUtils.java
License:Open Source License
/** * Return names of properties holding NaturalId of the given entity's * metadata./*from ww w .j a v a2 s . c o m*/ * * @param metadata entity class metadata * @return names of properties holding NaturalId */ public static String[] getNaturalIdentifierNames(ClassMetadata metadata) { if (!metadata.hasNaturalIdentifier()) { return new String[0]; } int[] naturalProps = metadata.getNaturalIdentifierProperties(); String[] propNames = metadata.getPropertyNames(); String[] naturalNames = new String[naturalProps.length]; for (int i = 0; i < naturalProps.length; i++) { naturalNames[i] = propNames[naturalProps[i]]; } return naturalNames; }
From source file:cz.jirutka.rsql.hibernate.builder.NaturalIdCriterionBuilder.java
License:Open Source License
/** * Check if given property associates an entity that has a natural * identifier. This doesn't check if property is an association type or even * if it exists!//from w ww.j a v a2s . c om * * @param property property name * @param builder parent <tt>CriteriaBuilder</tt> * @return <tt>true</tt> if given property associates an entity that has * a natural identifier, <tt>false</tt> otherwise * @throws HibernateException If entity does not contain such property or * it's not an association type. */ protected boolean hasNaturalIdentifier(String property, Class<?> entityClass, CriteriaBuilder builder) throws HibernateException { ClassMetadata classMetadata = builder.getClassMetadata(entityClass); if (classMetadata == null) { return false; } Class<?> type = findPropertyType(property, classMetadata); ClassMetadata assocClassMetadata = builder.getClassMetadata(type); return assocClassMetadata.hasNaturalIdentifier(); }
From source file:cz.jirutka.rsql.hibernate.NaturalIdCriterionBuilder.java
License:Open Source License
/** * Check if given property associates an entity that has a natural * identifier. This doesn't check if property is an association type or even * if it exists!/*from ww w. java 2 s .co m*/ * * @param property property name * @param builder parent <tt>CriteriaBuilder</tt> * @return <tt>true</tt> if given property associates an entity that has * a natural identifier, <tt>false</tt> otherwise * @throws HibernateException If entity does not contain such property or * it's not an association type. */ protected boolean hasNaturalIdentifier(String property, Class<?> entityClass, CriteriaBuilder builder) throws HibernateException { Class<?> type = findPropertyType(property, builder.getClassMetadata(entityClass)); ClassMetadata assocClassMetadata = builder.getClassMetadata(type); return assocClassMetadata.hasNaturalIdentifier(); }
From source file:es.logongas.ix3.dao.metadata.impl.MetaDataImplHibernate.java
License:Apache License
@Override public List<String> getNaturalKeyPropertiesName() { List<String> naturalKeyPropertiesName = new ArrayList<String>(); ClassMetadata classMetadata = getClassMetadata(); if (classMetadata == null) { return naturalKeyPropertiesName; }//from w w w . j a va 2 s . c o m if (classMetadata.hasNaturalIdentifier()) { int[] positions = classMetadata.getNaturalIdentifierProperties(); String[] propertyNames = classMetadata.getPropertyNames(); for (int i = 0; i < positions.length; i++) { int position = positions[i]; String naturalKeyPropertyName = propertyNames[position]; naturalKeyPropertiesName.add(naturalKeyPropertyName); } } else { //Si no hay clave natural, la lista no tendr ningn elemento } return naturalKeyPropertiesName; }