本文整理匯總了Java中javax.persistence.ManyToMany.fetch方法的典型用法代碼示例。如果您正苦於以下問題:Java ManyToMany.fetch方法的具體用法?Java ManyToMany.fetch怎麽用?Java ManyToMany.fetch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.persistence.ManyToMany
的用法示例。
在下文中一共展示了ManyToMany.fetch方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: defineFetchingStrategy
import javax.persistence.ManyToMany; //導入方法依賴的package包/類
private void defineFetchingStrategy() {
LazyCollection lazy = property.getAnnotation( LazyCollection.class );
Fetch fetch = property.getAnnotation( Fetch.class );
OneToMany oneToMany = property.getAnnotation( OneToMany.class );
ManyToMany manyToMany = property.getAnnotation( ManyToMany.class );
ElementCollection elementCollection = property.getAnnotation( ElementCollection.class ); //jpa 2
ManyToAny manyToAny = property.getAnnotation( ManyToAny.class );
FetchType fetchType;
if ( oneToMany != null ) {
fetchType = oneToMany.fetch();
}
else if ( manyToMany != null ) {
fetchType = manyToMany.fetch();
}
else if ( elementCollection != null ) {
fetchType = elementCollection.fetch();
}
else if ( manyToAny != null ) {
fetchType = FetchType.LAZY;
}
else {
throw new AssertionFailure(
"Define fetch strategy on a property not annotated with @ManyToOne nor @OneToMany nor @CollectionOfElements"
);
}
if ( lazy != null ) {
collection.setLazy( !( lazy.value() == LazyCollectionOption.FALSE ) );
collection.setExtraLazy( lazy.value() == LazyCollectionOption.EXTRA );
}
else {
collection.setLazy( fetchType == FetchType.LAZY );
collection.setExtraLazy( false );
}
if ( fetch != null ) {
if ( fetch.value() == org.hibernate.annotations.FetchMode.JOIN ) {
collection.setFetchMode( FetchMode.JOIN );
collection.setLazy( false );
}
else if ( fetch.value() == org.hibernate.annotations.FetchMode.SELECT ) {
collection.setFetchMode( FetchMode.SELECT );
}
else if ( fetch.value() == org.hibernate.annotations.FetchMode.SUBSELECT ) {
collection.setFetchMode( FetchMode.SELECT );
collection.setSubselectLoadable( true );
collection.getOwner().setSubselectLoadableCollections( true );
}
else {
throw new AssertionFailure( "Unknown FetchMode: " + fetch.value() );
}
}
else {
collection.setFetchMode( AnnotationBinder.getFetchMode( fetchType ) );
}
}
示例2: createAttribute
import javax.persistence.ManyToMany; //導入方法依賴的package包/類
@Override
protected MetaAttribute createAttribute(T metaDataObject, PropertyDescriptor desc) {
MetaEntityAttribute attr = new MetaEntityAttribute();
attr.setName(desc.getName());
attr.setParent(metaDataObject, true);
if (hasJpaAnnotations(attr)) {
ManyToMany manyManyAnnotation = attr.getAnnotation(ManyToMany.class);
ManyToOne manyOneAnnotation = attr.getAnnotation(ManyToOne.class);
OneToMany oneManyAnnotation = attr.getAnnotation(OneToMany.class);
OneToOne oneOneAnnotation = attr.getAnnotation(OneToOne.class);
Version versionAnnotation = attr.getAnnotation(Version.class);
ElementCollection elemCollectionAnnotation = attr.getAnnotation(ElementCollection.class);
attr.setVersion(versionAnnotation != null);
FetchType fetchType = null;
if (manyManyAnnotation != null) {
fetchType = manyManyAnnotation.fetch();
}
if (oneManyAnnotation != null) {
fetchType = oneManyAnnotation.fetch();
}
if (oneOneAnnotation != null) {
fetchType = oneOneAnnotation.fetch();
}
attr.setAssociation(manyManyAnnotation != null || manyOneAnnotation != null || oneManyAnnotation != null
|| oneOneAnnotation != null);
boolean lazyCollection = elemCollectionAnnotation != null
&& elemCollectionAnnotation.fetch() != FetchType.EAGER;
boolean lazyAssociation = attr.isAssociation() && (fetchType == null || fetchType == FetchType.LAZY);
attr.setLazy(lazyCollection || lazyAssociation);
} else {
attr.setDerived(true);
}
attr.setSortable(true);
attr.setFilterable(true);
return attr;
}