Java Code Examples for org.hibernate.mapping.PersistentClass#getProperty()

The following examples show how to use org.hibernate.mapping.PersistentClass#getProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VerifyFetchProfileReferenceSecondPass.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void doSecondPass(Map persistentClasses) throws MappingException {
	org.hibernate.mapping.FetchProfile profile = buildingContext.getMetadataCollector().getFetchProfile(
			fetchProfileName
	);
	if ( profile != null ) {
		if ( profile.getSource() != MetadataSource.ANNOTATIONS ) {
			return;
		}
	}
	else {
		profile = new org.hibernate.mapping.FetchProfile( fetchProfileName, MetadataSource.ANNOTATIONS );
		buildingContext.getMetadataCollector().addFetchProfile( profile );
	}

	PersistentClass clazz = buildingContext.getMetadataCollector().getEntityBinding( fetch.entity().getName() );
	// throws MappingException in case the property does not exist
	clazz.getProperty( fetch.association() );

	profile.addFetch(
			fetch.entity().getName(), fetch.association(), fetch.mode().toString().toLowerCase(Locale.ROOT)
	);
}
 
Example 2
Source File: ComponentTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void afterConfigurationBuilt(Mappings mappings, Dialect dialect) {
	super.afterConfigurationBuilt( mappings, dialect );
	// Oracle and Postgres do not have year() functions, so we need to
	// redefine the 'User.person.yob' formula
	//
	// consider temporary until we add the capability to define
	// mapping foprmulas which can use dialect-registered functions...
	PersistentClass user = mappings.getClass( User.class.getName() );
	org.hibernate.mapping.Property personProperty = user.getProperty( "person" );
	Component component = ( Component ) personProperty.getValue();
	Formula f = ( Formula ) component.getProperty( "yob" ).getValue().getColumnIterator().next();

	SQLFunction yearFunction = ( SQLFunction ) dialect.getFunctions().get( "year" );
	if ( yearFunction == null ) {
		// the dialect not know to support a year() function, so rely on the
		// ANSI SQL extract function
		f.setFormula( "extract( year from dob )");
	}
	else {
		List args = new ArrayList();
		args.add( "dob" );
		f.setFormula( yearFunction.render( args, null ) );
	}
}
 
Example 3
Source File: NonReflectiveBinderTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testComparator() {
	PersistentClass cm = cfg.getClassMapping("org.hibernate.test.legacy.Wicked");
	
	Property property = cm.getProperty("sortedEmployee");
	Collection col = (Collection) property.getValue();
	assertEquals(col.getComparatorClassName(),"org.hibernate.test.legacy.NonExistingComparator");
}
 
Example 4
Source File: InterfaceMetadataContributor.java    From mPaaS with Apache License 2.0 4 votes vote down vote up
/** 读取索引配置 */
private void readIndex(PersistentClass pclazz, Class<?> iface) {
	Table table = iface.getAnnotation(Table.class);
	if (table == null) {
		return;
	}
	org.hibernate.mapping.Table tb = pclazz.getTable();
	outloop: for (Index index : table.indexes()) {
		List<Identifier> columnNames = new ArrayList<>();
		org.hibernate.mapping.Index idx = new org.hibernate.mapping.Index();
		// columnList="fdId, fdName"
		String[] columns = index.columnList().split(",");
		for (String column : columns) {
			column = column.trim();
			int i = column.indexOf(' ');
			String order = null;
			if (i > -1) {
				order = column.substring(i).trim();
				column = column.substring(0, i);
			}
			Property property = pclazz.getProperty(column);
			org.hibernate.mapping.Column col = (org.hibernate.mapping.Column) property
					.getColumnIterator().next();
			if (col == null) {
				log.error(StringHelper.join(iface.getName(), "指定的索引列不存在:",
						column));
				continue outloop;
			}
			columnNames.add(Identifier.toIdentifier(column));
			idx.addColumn(col, order);
		}
		idx.setTable(tb);
		// 创建索引名称
		String name = index.name();
		if (StringUtils.isBlank(name)) {
			name = NamingHelper.INSTANCE.generateHashedConstraintName("IDX",
					idx.getTable().getNameIdentifier(), columnNames);
		}
		idx.setName(name);
		// 判断索引是否存在
		if (tb.getIndex(name) == null) {
			tb.addIndex(idx);
		}
	}
}