本文整理汇总了Java中javax.persistence.ManyToMany类的典型用法代码示例。如果您正苦于以下问题:Java ManyToMany类的具体用法?Java ManyToMany怎么用?Java ManyToMany使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ManyToMany类属于javax.persistence包,在下文中一共展示了ManyToMany类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMappedBy
import javax.persistence.ManyToMany; //导入依赖的package包/类
private String getMappedBy(MetaAttribute attr) {
ManyToMany manyManyAnnotation = attr.getAnnotation(ManyToMany.class);
OneToMany oneManyAnnotation = attr.getAnnotation(OneToMany.class);
OneToOne oneOneAnnotation = attr.getAnnotation(OneToOne.class);
String mappedBy = null;
if (manyManyAnnotation != null) {
mappedBy = manyManyAnnotation.mappedBy();
}
if (oneManyAnnotation != null) {
mappedBy = oneManyAnnotation.mappedBy();
}
if (oneOneAnnotation != null) {
mappedBy = oneOneAnnotation.mappedBy();
}
if (mappedBy != null && mappedBy.length() == 0) {
mappedBy = null;
}
return mappedBy;
}
示例2: getFieldType
import javax.persistence.ManyToMany; //导入依赖的package包/类
@Override
public Optional<ResourceFieldType> getFieldType(BeanAttributeInformation attributeDesc) {
Optional<OneToOne> oneToOne = attributeDesc.getAnnotation(OneToOne.class);
Optional<OneToMany> oneToMany = attributeDesc.getAnnotation(OneToMany.class);
Optional<ManyToOne> manyToOne = attributeDesc.getAnnotation(ManyToOne.class);
Optional<ManyToMany> manyToMany = attributeDesc.getAnnotation(ManyToMany.class);
if (oneToOne.isPresent() || oneToMany.isPresent() || manyToOne.isPresent() || manyToMany.isPresent()) {
return Optional.of(ResourceFieldType.RELATIONSHIP);
}
Optional<Id> id = attributeDesc.getAnnotation(Id.class);
Optional<EmbeddedId> embeddedId = attributeDesc.getAnnotation(EmbeddedId.class);
if (id.isPresent() || embeddedId.isPresent()) {
return Optional.of(ResourceFieldType.ID);
}
return Optional.empty();
}
示例3: getSerializeType
import javax.persistence.ManyToMany; //导入依赖的package包/类
@Override
public Optional<SerializeType> getSerializeType(BeanAttributeInformation attributeDesc) {
Optional<OneToMany> oneToMany = attributeDesc.getAnnotation(OneToMany.class);
if (oneToMany.isPresent()) {
return toSerializeType(oneToMany.get().fetch());
}
Optional<ManyToOne> manyToOne = attributeDesc.getAnnotation(ManyToOne.class);
if (manyToOne.isPresent()) {
return toSerializeType(manyToOne.get().fetch());
}
Optional<ManyToMany> manyToMany = attributeDesc.getAnnotation(ManyToMany.class);
if (manyToMany.isPresent()) {
return toSerializeType(manyToMany.get().fetch());
}
Optional<ElementCollection> elementCollection = attributeDesc.getAnnotation(ElementCollection.class);
if (elementCollection.isPresent()) {
return toSerializeType(elementCollection.get().fetch());
}
return Optional.empty();
}
示例4: getPlmVersions
import javax.persistence.ManyToMany; //导入依赖的package包/类
/** @return . */
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "PLM_ISSUE_VERSION", joinColumns = { @JoinColumn(name = "ISSUE_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "VERSION_ID", nullable = false, updatable = false) })
public Set<PlmVersion> getPlmVersions() {
return this.plmVersions;
}
示例5: hasAnnotationsOnIdClass
import javax.persistence.ManyToMany; //导入依赖的package包/类
private static boolean hasAnnotationsOnIdClass(XClass idClass) {
// if(idClass.getAnnotation(Embeddable.class) != null)
// return true;
List<XProperty> properties = idClass.getDeclaredProperties( XClass.ACCESS_FIELD );
for ( XProperty property : properties ) {
if ( property.isAnnotationPresent( Column.class ) || property.isAnnotationPresent( OneToMany.class ) ||
property.isAnnotationPresent( ManyToOne.class ) || property.isAnnotationPresent( Id.class ) ||
property.isAnnotationPresent( GeneratedValue.class ) || property.isAnnotationPresent( OneToOne.class ) ||
property.isAnnotationPresent( ManyToMany.class )
) {
return true;
}
}
List<XMethod> methods = idClass.getDeclaredMethods();
for ( XMethod method : methods ) {
if ( method.isAnnotationPresent( Column.class ) || method.isAnnotationPresent( OneToMany.class ) ||
method.isAnnotationPresent( ManyToOne.class ) || method.isAnnotationPresent( Id.class ) ||
method.isAnnotationPresent( GeneratedValue.class ) || method.isAnnotationPresent( OneToOne.class ) ||
method.isAnnotationPresent( ManyToMany.class )
) {
return true;
}
}
return false;
}
示例6: appendEntityAttributeName
import javax.persistence.ManyToMany; //导入依赖的package包/类
/**
*
* Append the entity attribute name to the JPQL query statement.
*
* @param jpqlStatement
* @param jpaEntity
* @param attribute
* @throws java.lang.SecurityException
* @throws NoSuchFieldException
* @throws ClassNotFoundException
*/
private void appendEntityAttributeName(StringBuilder jpqlStatement, JpaEntity jpaEntity, EntityAttribute attribute, AtomicInteger aliasUnicityKey, AtomicInteger joinAdditionsOffset) throws NoSuchFieldException, java.lang.SecurityException, ClassNotFoundException {
Class<?> entityClass = Class.forName(jpaEntity.getClassName());
Field field = entityClass.getDeclaredField(attribute.getAttributeName());
boolean isJointRelationship =
field.getAnnotation(OneToOne.class) != null
|| field.getAnnotation(OneToMany.class) != null
|| field.getAnnotation(ManyToOne.class) != null
|| field.getAnnotation(ManyToMany.class) != null;
if(isJointRelationship) {
StringBuilder joinFragment = new StringBuilder();
Queue<String> objectTreePath = extractDotSeparatedPathFragments(attribute.getPossibleValueLabelAttributePath());
completeJoinFragment(joinFragment, entityClass, objectTreePath, aliasUnicityKey);
jpqlStatement.insert(joinAdditionsOffset.get(), joinFragment);
joinAdditionsOffset.set(joinAdditionsOffset.get() + joinFragment.length());
jpqlStatement.append(" x").append(aliasUnicityKey.get()).append('.').append(attribute.getPossibleValueLabelAttribute());
} else {
jpqlStatement.append(" x.").append(attribute.getAttributeName());
}
}
示例7: buildFieldInfo
import javax.persistence.ManyToMany; //导入依赖的package包/类
protected FieldInfo buildFieldInfo(Field field) {
FieldInfo info = new FieldInfo();
info.setName(field.getName());
info.setGenericType(field.getGenericType());
ManyToMany manyToMany = field.getAnnotation(ManyToMany.class);
if (manyToMany != null) {
info.setManyToManyMappedBy(manyToMany.mappedBy());
info.setManyToManyTargetEntity(manyToMany.targetEntity().getName());
}
OneToMany oneToMany = field.getAnnotation(OneToMany.class);
if (oneToMany != null) {
info.setOneToManyMappedBy(oneToMany.mappedBy());
info.setOneToManyTargetEntity(oneToMany.targetEntity().getName());
}
MapKey mapKey = field.getAnnotation(MapKey.class);
if (mapKey != null) {
info.setMapKey(mapKey.name());
}
return info;
}
示例8: buildFieldInfo
import javax.persistence.ManyToMany; //导入依赖的package包/类
protected FieldInfo buildFieldInfo(Field field) {
FieldInfo info = new FieldInfo();
info.setName(field.getName());
info.setGenericType(field.getGenericType());
ManyToMany manyToMany = field.getAnnotation(ManyToMany.class);
if (manyToMany != null) {
info.setManyToManyMappedBy(manyToMany.mappedBy());
info.setManyToManyTargetEntity(manyToMany.targetEntity().getName());
}
OneToMany oneToMany = field.getAnnotation(OneToMany.class);
if (oneToMany != null) {
info.setOneToManyMappedBy(oneToMany.mappedBy());
info.setOneToManyTargetEntity(oneToMany.targetEntity().getName());
}
return info;
}
示例9: mappedByAnything
import javax.persistence.ManyToMany; //导入依赖的package包/类
private Annotation mappedByAnything(String property) {
Field field = findField(property);
Annotation relationAnnotation = null;
relationAnnotation = field.getAnnotation(ManyToMany.class);
if (relationAnnotation != null) {
return relationAnnotation;
}
relationAnnotation = field.getAnnotation(OneToOne.class);
if (relationAnnotation != null) {
return relationAnnotation;
}
relationAnnotation = field.getAnnotation(OneToMany.class);
if (relationAnnotation != null) {
return relationAnnotation;
}
relationAnnotation = field.getAnnotation(ManyToOne.class);
if (relationAnnotation != null) {
return relationAnnotation;
}
return null;
}
示例10: getChildren
import javax.persistence.ManyToMany; //导入依赖的package包/类
@ReadPermission(expression = "allow all OR deny all")
@UpdatePermission(expression = "allow all OR deny all")
// Hibernate
@ManyToMany(
targetEntity = Child.class,
cascade = { CascadeType.PERSIST, CascadeType.MERGE }
)
@JoinTable(
name = "Parent_Child",
joinColumns = @JoinColumn(name = "parent_id"),
inverseJoinColumns = @JoinColumn(name = "child_id")
)
@NotNull
public Set<Child> getChildren() {
return children;
}
示例11: anyAnnotation
import javax.persistence.ManyToMany; //导入依赖的package包/类
private Annotation anyAnnotation(Field field) {
Annotation annotation = null;
annotation = field.getAnnotation(ManyToMany.class);
if (annotation != null) {
return annotation;
}
annotation = field.getAnnotation(OneToOne.class);
if (annotation != null) {
return annotation;
}
annotation = field.getAnnotation(OneToMany.class);
if (annotation != null) {
return annotation;
}
annotation = field.getAnnotation(ManyToOne.class);
if (annotation != null) {
return annotation;
}
return null;
}
示例12: targetEntity
import javax.persistence.ManyToMany; //导入依赖的package包/类
private Class<?> targetEntity(Annotation relationAnnotation) {
if (relationAnnotation instanceof ManyToMany) {
return ManyToMany.class.cast(relationAnnotation).targetEntity();
}
if (relationAnnotation instanceof OneToOne) {
return OneToOne.class.cast(relationAnnotation).targetEntity();
}
if (relationAnnotation instanceof OneToMany) {
return OneToMany.class.cast(relationAnnotation).targetEntity();
}
if (relationAnnotation instanceof ManyToOne) {
return ManyToOne.class.cast(relationAnnotation).targetEntity();
}
return null;
}
示例13: needsToCascade
import javax.persistence.ManyToMany; //导入依赖的package包/类
private static boolean needsToCascade(Field field) {
Class<?> fieldtype = field.getType();
if (!DomainObject.class.isAssignableFrom(fieldtype))
return false;
Annotation ann;
CascadeType[] cascades = null;
ann = field.getAnnotation(OneToOne.class);
if (ann != null) {
cascades = ((OneToOne) ann).cascade();
} else {
ann = field.getAnnotation(OneToMany.class);
if (ann != null) {
cascades = ((OneToMany) ann).cascade();
} else {
ann = field.getAnnotation(ManyToOne.class);
if (ann != null) {
cascades = ((ManyToOne) ann).cascade();
} else {
ann = field.getAnnotation(ManyToMany.class);
if (ann != null) {
cascades = ((ManyToMany) ann).cascade();
}
}
}
}
if (cascades == null)
return false;
for (CascadeType cas : cascades) {
if ((cas == CascadeType.ALL) || (cas == CascadeType.MERGE)
|| (cas == CascadeType.PERSIST)
|| (cas == CascadeType.REMOVE)) {
return true;
}
}
return false;
}
示例14: getOppositeName
import javax.persistence.ManyToMany; //导入依赖的package包/类
@Override
public Optional<String> getOppositeName(BeanAttributeInformation attributeDesc) {
Optional<OneToMany> oneToMany = attributeDesc.getAnnotation(OneToMany.class);
if (oneToMany.isPresent()) {
return Optional.ofNullable(StringUtils.emptyToNull(oneToMany.get().mappedBy()));
}
Optional<ManyToMany> manyToMany = attributeDesc.getAnnotation(ManyToMany.class);
if (manyToMany.isPresent()) {
return Optional.ofNullable(StringUtils.emptyToNull(manyToMany.get().mappedBy()));
}
return Optional.empty();
}
示例15: isManyToMany
import javax.persistence.ManyToMany; //导入依赖的package包/类
public boolean isManyToMany()
{
if( isManyToMany == null )
{
isManyToMany = getAnnotation(ManyToMany.class) != null;
}
return isManyToMany;
}