Java Code Examples for org.hibernate.type.EntityType#getAssociatedJoinable()

The following examples show how to use org.hibernate.type.EntityType#getAssociatedJoinable() . 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: JoinHelper.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private static String[] determineRhsColumnNames(EntityType entityType, SessionFactoryImplementor sessionFactory) {
	final Joinable persister = entityType.getAssociatedJoinable( sessionFactory );
	return entityType.getRHSUniqueKeyPropertyName() == null ?
			persister.getKeyColumnNames() :
			( (PropertyMapping) persister ).toColumns( entityType.getRHSUniqueKeyPropertyName() );
}
 
Example 2
Source File: MapKeyEntityFromElement.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public static MapKeyEntityFromElement buildKeyJoin(FromElement collectionFromElement) {
		final HqlSqlWalker walker = collectionFromElement.getWalker();
		final SessionFactoryHelper sfh = walker.getSessionFactoryHelper();
		final SessionFactoryImplementor sf = sfh.getFactory();

		final QueryableCollection collectionPersister = collectionFromElement.getQueryableCollection();
		final Type indexType = collectionPersister.getIndexType();
		if ( indexType == null ) {
			throw new IllegalArgumentException( "Given collection is not indexed" );
		}
		if ( !indexType.isEntityType() ) {
			throw new IllegalArgumentException( "Given collection does not have an entity index" );
		}

		final EntityType indexEntityType = (EntityType) indexType;
		final EntityPersister indexEntityPersister = (EntityPersister) indexEntityType.getAssociatedJoinable( sf );

		final String rhsAlias = walker.getAliasGenerator().createName( indexEntityPersister.getEntityName() );
		final boolean useThetaJoin = collectionFromElement.getJoinSequence().isThetaStyle();

		MapKeyEntityFromElement join = new MapKeyEntityFromElement( useThetaJoin );
		join.initialize( HqlSqlTokenTypes.JOIN_FRAGMENT, ( (Joinable) indexEntityPersister ).getTableName() );
		join.initialize( collectionFromElement.getWalker() );

		join.initializeEntity(
				collectionFromElement.getFromClause(),
				indexEntityPersister.getEntityName(),
				indexEntityPersister,
				indexEntityType,
				"<map-key-join-" + collectionFromElement.getClassAlias() + ">",
				rhsAlias
		);

//		String[] joinColumns = determineJoinColuns( collectionPersister, joinTableAlias );
		// todo : assumes columns, no formulas
		String[] joinColumns = collectionPersister.getIndexColumnNames( collectionFromElement.getCollectionTableAlias() );

		JoinSequence joinSequence = sfh.createJoinSequence(
				useThetaJoin,
				indexEntityType,
				rhsAlias,
				// todo : ever a time when INNER is appropriate?
				//JoinType.LEFT_OUTER_JOIN,
				// needs to be an inner join because of how JoinSequence/JoinFragment work - ugh
//				JoinType.INNER_JOIN,
				collectionFromElement.getJoinSequence().getFirstJoin().getJoinType(),
				joinColumns
		);
		join.setJoinSequence( joinSequence );

		join.setOrigin( collectionFromElement, true );
		join.setColumns( joinColumns );

		join.setUseFromFragment( collectionFromElement.useFromFragment() );
		join.setUseWhereFragment( collectionFromElement.useWhereFragment() );

		walker.addQuerySpaces( indexEntityPersister.getQuerySpaces() );

		return join;
	}