下面列出了怎么用org.hibernate.annotations.FetchProfile的API类实例代码及写法,或者点击链接到github查看源代码。
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)
);
}
private static void bindFetchProfile(FetchProfile fetchProfileAnnotation, MetadataBuildingContext context) {
for ( FetchProfile.FetchOverride fetch : fetchProfileAnnotation.fetchOverrides() ) {
org.hibernate.annotations.FetchMode mode = fetch.mode();
if ( !mode.equals( org.hibernate.annotations.FetchMode.JOIN ) ) {
throw new MappingException( "Only FetchMode.JOIN is currently supported" );
}
context.getMetadataCollector().addSecondPass(
new VerifyFetchProfileReferenceSecondPass(
fetchProfileAnnotation.name(),
fetch,
context
)
);
}
}
public VerifyFetchProfileReferenceSecondPass(
String fetchProfileName,
FetchProfile.FetchOverride fetch,
MetadataBuildingContext buildingContext) {
this.fetchProfileName = fetchProfileName;
this.fetch = fetch;
this.buildingContext = buildingContext;
}
private static void bindFetchProfiles(XAnnotatedElement annotatedElement, MetadataBuildingContext context) {
FetchProfile fetchProfileAnnotation = annotatedElement.getAnnotation( FetchProfile.class );
FetchProfiles fetchProfileAnnotations = annotatedElement.getAnnotation( FetchProfiles.class );
if ( fetchProfileAnnotation != null ) {
bindFetchProfile( fetchProfileAnnotation, context );
}
if ( fetchProfileAnnotations != null ) {
for ( FetchProfile profile : fetchProfileAnnotations.value() ) {
bindFetchProfile( profile, context );
}
}
}