下面列出了javax.persistence.Enumerated#javax.persistence.FetchType 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected boolean isJpaLazy(Collection<Annotation> annotations, boolean isAssociation) {
for (Annotation annotation : annotations) {
if (annotation instanceof OneToMany) {
OneToMany oneToMany = (OneToMany) annotation;
return oneToMany.fetch() == FetchType.LAZY;
}
if (annotation instanceof ManyToOne) {
ManyToOne manyToOne = (ManyToOne) annotation;
return manyToOne.fetch() == FetchType.LAZY;
}
if (annotation instanceof ManyToMany) {
ManyToMany manyToMany = (ManyToMany) annotation;
return manyToMany.fetch() == FetchType.LAZY;
}
if (annotation instanceof ElementCollection) {
ElementCollection elementCollection = (ElementCollection) annotation;
return elementCollection.fetch() == FetchType.LAZY;
}
}
return isAssociation;
}
@XmlTransient
@LazyCollection(LazyCollectionOption.EXTRA)
@ManyToMany(fetch=FetchType.LAZY, cascade=CascadeType.ALL)
@JoinTable(name = "role_mappings", joinColumns = {
@JoinColumn(name = "user_id", nullable = false, updatable = false) },
inverseJoinColumns = { @JoinColumn(name = "role",
nullable = false, updatable = false) })
public List<Role> getRoles() {return _roles;}
public static FetchMode getFetchMode(FetchType fetch) {
if ( fetch == FetchType.EAGER ) {
return FetchMode.JOIN;
}
else {
return FetchMode.SELECT;
}
}
private void getFetchType(AnnotationDescriptor descriptor, Element element) {
String fetchString = element != null ? element.attributeValue( "fetch" ) : null;
if ( fetchString != null ) {
if ( "eager".equalsIgnoreCase( fetchString ) ) {
descriptor.setValue( "fetch", FetchType.EAGER );
}
else if ( "lazy".equalsIgnoreCase( fetchString ) ) {
descriptor.setValue( "fetch", FetchType.LAZY );
}
}
}
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "org_role_resource_rel",
joinColumns = {@JoinColumn(name = "role_id")},
inverseJoinColumns = {@JoinColumn(name = "resources_id")})
public Set<Resource> getResources() {
return resources;
}
/**
* @return the installed products
*/
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "suseImageInfoInstalledProduct",
joinColumns = {
@JoinColumn(name = "image_info_id", nullable = false, updatable = false)},
inverseJoinColumns = {
@JoinColumn(name = "installed_product_id", nullable = false, updatable = false)
})
public Set<InstalledProduct> getInstalledProducts() {
return installedProducts;
}
/**
* @return the patches
*/
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "rhnImageNeededErrataCache",
joinColumns = {@JoinColumn(name = "image_id")},
inverseJoinColumns = {@JoinColumn(name = "errata_id")}
)
public Set<PublishedErrata> getPatches() {
return patches;
}
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "org_user_role_rel",
joinColumns = {@JoinColumn(name = "user_id")},
inverseJoinColumns = {@JoinColumn(name = "role_id")})
@Where(clause="delete_flag=0")
@OrderBy("no")
public Set<Role> getRoles() {
return roles;
}
/**
* @return the tableproperty
*/
@Where(clause="impfield=0") //不载入 设置为 禁用 导入导出的字段
@OneToMany(cascade = CascadeType.ALL,fetch = FetchType.EAGER)
@JoinColumn(name = "dbtableid")
@OrderBy("sortindex")
public List<TableProperties> getTableproperty() {
return tableproperty;
}
/**
* @return the channels
*/
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "suseImageInfoChannel",
joinColumns = {
@JoinColumn(name = "image_info_id", nullable = false, updatable = false)},
inverseJoinColumns = {
@JoinColumn(name = "channel_id", nullable = false, updatable = false)}
)
public Set<Channel> getChannels() {
return channels;
}
/**
* @return Returns the key.
*/
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "key_id", nullable = false)
public CustomDataKey getKey() {
return key;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "group_code_id", insertable = false, updatable = false)
public AdmBasekeyCode getGroupBasekeyCode() {
return this.groupBasekeyCode;
}
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 );
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 ) );
}
}
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "operation", insertable = false, updatable = false)
public AdmBasekeyCode getOperationCode() {
return operationCode;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parent_id_adm_role")
public AdmRole getAdmRole() {
return this.admRole;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id_adm_tenement")
public AdmTenement getAdmTenement() {
return this.admTenement;
}
@OneToMany(mappedBy = "funcionario", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
public List<Lancamento> getLancamentos() {
return lancamentos;
}
/**
* @return the custom data values
*/
@OneToMany(fetch = FetchType.LAZY, mappedBy = "profile")
public Set<ProfileCustomDataValue> getCustomDataValues() {
return customDataValues;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id_adm_user")
public AdmUser getAdmUser() {
return this.admUser;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id_adm_tenement")
public AdmTenement getAdmTenement() {
return this.admTenement;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id_adm_role", insertable = false, updatable = false)
public AdmRole getAdmRole() {
return this.admRole;
}
@XmlTransient
@OneToOne(cascade=CascadeType.ALL, orphanRemoval=true, optional=true, fetch=FetchType.LAZY)
public Media getProfilePicture() {return _pic;}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id_adm_ci_type_attr")
public AdmCiTypeAttr getAdmCiTypeAttr() {
return this.admCiTypeAttr;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id_adm_attr_group")
public AdmAttrGroup getAdmAttrGroup() {
return this.admAttrGroup;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id_adm_ci_type_attr")
public AdmCiTypeAttr getAdmCiTypeAttr() {
return this.admCiTypeAttr;
}
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
public Address getAddress() {
return address;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id_adm_basekey_cat_type", insertable = false, updatable = false)
public AdmBasekeyCatType getAdmBasekeyCatType() {
return this.admBasekeyCatType;
}
private static void bindAny(
String cascadeStrategy,
Ejb3JoinColumn[] columns,
boolean cascadeOnDelete,
Nullability nullability,
PropertyHolder propertyHolder,
PropertyData inferredData,
EntityBinder entityBinder,
boolean isIdentifierMapper,
MetadataBuildingContext buildingContext) {
org.hibernate.annotations.Any anyAnn = inferredData.getProperty()
.getAnnotation( org.hibernate.annotations.Any.class );
if ( anyAnn == null ) {
throw new AssertionFailure(
"Missing @Any annotation: "
+ BinderHelper.getPath( propertyHolder, inferredData )
);
}
Any value = BinderHelper.buildAnyValue(
anyAnn.metaDef(),
columns,
anyAnn.metaColumn(),
inferredData,
cascadeOnDelete,
nullability,
propertyHolder,
entityBinder,
anyAnn.optional(),
buildingContext
);
PropertyBinder binder = new PropertyBinder();
binder.setName( inferredData.getPropertyName() );
binder.setValue( value );
binder.setLazy( anyAnn.fetch() == FetchType.LAZY );
//binder.setCascade(cascadeStrategy);
if ( isIdentifierMapper ) {
binder.setInsertable( false );
binder.setUpdatable( false );
}
else {
binder.setInsertable( columns[0].isInsertable() );
binder.setUpdatable( columns[0].isUpdatable() );
}
binder.setAccessType( inferredData.getDefaultAccess() );
binder.setCascade( cascadeStrategy );
Property prop = binder.makeProperty();
//composite FK columns are in the same table so its OK
propertyHolder.addProperty( prop, columns, inferredData.getDeclaringClass() );
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id_adm_role", insertable = false, updatable = false)
public AdmRole getAdmRole() {
return this.admRole;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id_adm_user", insertable = false, updatable = false)
public AdmUser getAdmUser() {
return this.admUser;
}