Java Code Examples for javax.persistence.OneToMany

The following are top voted examples for showing how to use javax.persistence.OneToMany. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: crnk-framework   File: JpaMetaFilter.java   View source code 6 votes vote down vote up
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;
}
 
Example 2
Project: crnk-framework   File: JpaResourceFieldInformationProvider.java   View source code 6 votes vote down vote up
@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();
}
 
Example 3
Project: sbc-qsystem   File: QUser.java   View source code 6 votes vote down vote up
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
@JoinColumn(name = "user_id", insertable = false, nullable = false, updatable = false)
// MOSCOW
@Fetch(FetchMode.SELECT)
// Это отсечение дублирования при джойне таблици, т.к. в QPlanService есть @OneToOne к QService, и в нем есть @OneToMany к QServiceLang - дублится по
// количеству переводов
// This is the truncation of the duplication when the table joins, since In QPlanService there is @OneToOne to QService, and there is @OneToMany to
// QServiceLang - it is duplicated by the number of translations.
public List<QPlanService> getPlanServices() {
    return planServices;
}
 
Example 4
Project: Equella   File: LanguageBundle.java   View source code 5 votes vote down vote up
@OneToMany(cascade = CascadeType.ALL, mappedBy = "bundle")
@Fetch(value = FetchMode.SELECT)
@MapKey(name = "locale")
public Map<String, LanguageString> getStrings()
{
	return strings;
}
 
Example 5
Project: lams   File: EnhancementTask.java   View source code 5 votes vote down vote up
@Override
public boolean isMappedCollection(CtField field) {
    try {
        return (field.getAnnotation(OneToMany.class) != null ||
                field.getAnnotation(ManyToMany.class) != null ||
                field.getAnnotation(ElementCollection.class) != null);
    }
    catch (ClassNotFoundException e) {
        return false;
    }
}
 
Example 6
Project: oscm   File: ReflectiveClone.java   View source code 5 votes vote down vote up
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;
}
 
Example 7
Project: crnk-framework   File: JpaResourceFieldInformationProvider.java   View source code 5 votes vote down vote up
@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();
}
 
Example 8
Project: lams   File: PropertyContainer.java   View source code 5 votes vote down vote up
private static boolean discoverTypeWithoutReflection(XProperty p) {
	if ( p.isAnnotationPresent( OneToOne.class ) && !p.getAnnotation( OneToOne.class )
			.targetEntity()
			.equals( void.class ) ) {
		return true;
	}
	else if ( p.isAnnotationPresent( OneToMany.class ) && !p.getAnnotation( OneToMany.class )
			.targetEntity()
			.equals( void.class ) ) {
		return true;
	}
	else if ( p.isAnnotationPresent( ManyToOne.class ) && !p.getAnnotation( ManyToOne.class )
			.targetEntity()
			.equals( void.class ) ) {
		return true;
	}
	else if ( p.isAnnotationPresent( ManyToMany.class ) && !p.getAnnotation( ManyToMany.class )
			.targetEntity()
			.equals( void.class ) ) {
		return true;
	}
	else if ( p.isAnnotationPresent( org.hibernate.annotations.Any.class ) ) {
		return true;
	}
	else if ( p.isAnnotationPresent( ManyToAny.class ) ) {
		if ( !p.isCollection() && !p.isArray() ) {
			throw new AnnotationException( "@ManyToAny used on a non collection non array property: " + p.getName() );
		}
		return true;
	}
	else if ( p.isAnnotationPresent( Type.class ) ) {
		return true;
	}
	else if ( p.isAnnotationPresent( Target.class ) ) {
		return true;
	}
	return false;
}
 
Example 9
Project: java-course   File: BlogEntry.java   View source code 5 votes vote down vote up
/**
 * Get all comments for current blog entry.
 * 
 * @return List of all comments for current blog entry.
 */
@OneToMany(mappedBy = "blogEntry", fetch = FetchType.LAZY,
        cascade = CascadeType.PERSIST, orphanRemoval = true)
@OrderBy("postedOn")
public List<BlogComment> getComments() {
    return comments;
}
 
Example 10
Project: jkes   File: EventSupport.java   View source code 5 votes vote down vote up
private CascadeType[] getCascadeTypes(AccessibleObject accessibleObject) {
    CascadeType[] cascadeTypes = null;
    if(accessibleObject.isAnnotationPresent(OneToMany.class)) {
        cascadeTypes = accessibleObject.getAnnotation(OneToMany.class).cascade();
    }else if(accessibleObject.isAnnotationPresent(ManyToOne.class)) {
        cascadeTypes = accessibleObject.getAnnotation(ManyToOne.class).cascade();
    }else if(accessibleObject.isAnnotationPresent(ManyToMany.class)) {
        cascadeTypes = accessibleObject.getAnnotation(ManyToMany.class).cascade();
    }
    return cascadeTypes;
}
 
Example 11
Project: tinyshop8   File: GoodsBrand8JPA.java   View source code 5 votes vote down vote up
@OneToMany(targetEntity = Goods8JPA.class, cascade = REMOVE,
          fetch = EAGER)
@JoinColumn(name = "join_goods_brand_m2o", foreignKey =
@ForeignKey(name = "fk_goods_brand_m2o"))
@JoinTable(name = "jpa_goods_brand_set", foreignKey =
@ForeignKey(name = "fk_jpa_goods_brand_set"))
public Set<Goods8JPA> getGoods8JPASet()
{
    return goods8JPASet;
}
 
Example 12
Project: lemon   File: DiskShare.java   View source code 4 votes vote down vote up
/** @return . */
@OneToMany(fetch = FetchType.LAZY, mappedBy = "diskShare")
public Set<DiskAcl> getDiskAcls() {
    return this.diskAcls;
}
 
Example 13
Project: GitHub   File: Product.java   View source code 4 votes vote down vote up
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="product")
public Set<OrderDetail> getOrderDetails() {
    return this.orderDetails;
}
 
Example 14
Project: GitHub   File: Office.java   View source code 4 votes vote down vote up
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="office")
public Set<Employee> getEmployees() {
    return this.employees;
}
 
Example 15
Project: DocIT   File: Company.java   View source code 4 votes vote down vote up
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER, mappedBy="company")
public Set<Employee> getEmployees() {
    return this.employees;
}
 
Example 16
Project: DocIT   File: Department.java   View source code 4 votes vote down vote up
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="department")
public Set<Employee> getEmployees() {
    return this.employees;
}
 
Example 17
Project: DocIT   File: Department.java   View source code 4 votes vote down vote up
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="department")
public Set<Department> getDepartments() {
    return this.departments;
}
 
Example 18
Project: lemon   File: WhitelistPackage.java   View source code 4 votes vote down vote up
/** @return . */
@OneToMany(fetch = FetchType.LAZY, mappedBy = "whitelistPackage")
public Set<WhitelistService> getWhitelistServices() {
    return this.whitelistServices;
}
 
Example 19
Project: plumdo-work   File: SystemMenu.java   View source code 4 votes vote down vote up
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "systemMenu")
public Set<SystemMenu> getSystemMenus() {
	return this.systemMenus;
}
 
Example 20
Project: lemon   File: TicketCatalog.java   View source code 4 votes vote down vote up
/** @return . */
@OneToMany(fetch = FetchType.LAZY, mappedBy = "ticketCatalog")
public Set<TicketInfo> getTicketInfos() {
    return this.ticketInfos;
}
 
Example 21
Project: aws-photosharing-example   File: User.java   View source code 4 votes vote down vote up
@XmlTransient
@LazyCollection(LazyCollectionOption.EXTRA)
@OneToMany(mappedBy = "user", orphanRemoval=true, fetch=FetchType.LAZY, cascade=CascadeType.ALL)
public List<Share> getShares() {return shares;}
 
Example 22
Project: lemon   File: TicketGroup.java   View source code 4 votes vote down vote up
/** @return . */
@OneToMany(fetch = FetchType.LAZY, mappedBy = "ticketGroup")
public Set<TicketMember> getTicketMembers() {
    return this.ticketMembers;
}
 
Example 23
Project: lemon   File: BookInfo.java   View source code 4 votes vote down vote up
/** @return . */
@OneToMany(fetch = FetchType.LAZY, mappedBy = "bookInfo")
public Set<BookBorrow> getBookBorrows() {
    return this.bookBorrows;
}
 
Example 24
Project: lemon   File: FeedbackCatalog.java   View source code 4 votes vote down vote up
/** @return . */
@OneToMany(fetch = FetchType.LAZY, mappedBy = "feedbackCatalog")
public Set<FeedbackInfo> getFeedbackInfos() {
    return this.feedbackInfos;
}
 
Example 25
Project: aws-photosharing-example   File: Album.java   View source code 4 votes vote down vote up
@OneToMany(mappedBy = "album", orphanRemoval=true)    
@LazyCollection(LazyCollectionOption.EXTRA)
public List<Share> getShares() {return shares;}
 
Example 26
Project: lemon   File: BpmCategory.java   View source code 4 votes vote down vote up
/** @return . */
@OneToMany(fetch = FetchType.LAZY, mappedBy = "bpmCategory")
@OrderBy("priority")
public Set<BpmProcess> getBpmProcesses() {
    return this.bpmProcesses;
}
 
Example 27
Project: lemon   File: WhitelistService.java   View source code 4 votes vote down vote up
/** @return . */
@OneToMany(fetch = FetchType.LAZY, mappedBy = "whitelistService")
public Set<WhitelistInfo> getWhitelistInfos() {
    return this.whitelistInfos;
}
 
Example 28
Project: lemon   File: BpmProcess.java   View source code 4 votes vote down vote up
/** @return . */
@OneToMany(fetch = FetchType.LAZY, mappedBy = "bpmProcess")
public Set<BpmTaskDefNotice> getBpmTaskDefNotices() {
    return this.bpmTaskDefNotices;
}
 
Example 29
Project: lemon   File: BpmProcess.java   View source code 4 votes vote down vote up
/** @return . */
@OneToMany(fetch = FetchType.LAZY, mappedBy = "bpmProcess")
public Set<BpmInstance> getBpmInstances() {
    return this.bpmInstances;
}
 
Example 30
Project: lemon   File: JavamailConfig.java   View source code 4 votes vote down vote up
/** @return . */
@OneToMany(fetch = FetchType.LAZY, mappedBy = "javamailConfig")
public Set<JavamailMessage> getJavamailMessages() {
    return this.javamailMessages;
}
 
Example 31
Project: lemon   File: BpmConfNode.java   View source code 4 votes vote down vote up
/** @return . */
@OneToMany(fetch = FetchType.LAZY, mappedBy = "bpmConfNode")
public Set<BpmConfNotice> getBpmConfNotices() {
    return this.bpmConfNotices;
}
 
Example 32
Project: lemon   File: BpmConfNode.java   View source code 4 votes vote down vote up
/** @return . */
@OneToMany(fetch = FetchType.LAZY, mappedBy = "bpmConfNode")
public Set<BpmConfUser> getBpmConfUsers() {
    return this.bpmConfUsers;
}
 
Example 33
Project: tap17-muggl-javaee   File: Vendor.java   View source code 4 votes vote down vote up
@OneToMany(cascade=ALL, mappedBy="vendor")
public Collection<VendorPart> getVendorParts() {
    return vendorParts;
}
 
Example 34
Project: lemon   File: OfficesupplyInfo.java   View source code 4 votes vote down vote up
/** @return . */
@OneToMany(fetch = FetchType.LAZY, mappedBy = "officesupplyInfo")
public Set<OfficesupplyReceive> getOfficesupplyReceives() {
    return this.officesupplyReceives;
}
 
Example 35
Project: lemon   File: PimSchedule.java   View source code 4 votes vote down vote up
/** @return . */
@OneToMany(fetch = FetchType.LAZY, mappedBy = "pimSchedule")
public Set<PimScheduleParticipant> getPimScheduleParticipants() {
    return this.pimScheduleParticipants;
}
 
Example 36
Project: lemon   File: CmsArticle.java   View source code 4 votes vote down vote up
/** @return . */
@OneToMany(fetch = FetchType.LAZY, mappedBy = "cmsArticle")
public Set<CmsClick> getCmsClicks() {
    return this.cmsClicks;
}
 
Example 37
Project: lemon   File: BpmConfNode.java   View source code 4 votes vote down vote up
/** @return . */
@OneToMany(fetch = FetchType.LAZY, mappedBy = "bpmConfNode")
public Set<BpmConfOperation> getBpmConfOperations() {
    return this.bpmConfOperations;
}
 
Example 38
Project: lams   File: CollectionBinder.java   View source code 4 votes vote down vote up
protected void bindOneToManySecondPass(
		Collection collection,
		Map persistentClasses,
		Ejb3JoinColumn[] fkJoinColumns,
		XClass collectionType,
		boolean cascadeDeleteEnabled,
		boolean ignoreNotFound,
		Mappings mappings,
		Map<XClass, InheritanceState> inheritanceStatePerClass) {

	final boolean debugEnabled = LOG.isDebugEnabled();
	if ( debugEnabled ) {
		LOG.debugf( "Binding a OneToMany: %s.%s through a foreign key", propertyHolder.getEntityName(), propertyName );
	}
	org.hibernate.mapping.OneToMany oneToMany = new org.hibernate.mapping.OneToMany( mappings, collection.getOwner() );
	collection.setElement( oneToMany );
	oneToMany.setReferencedEntityName( collectionType.getName() );
	oneToMany.setIgnoreNotFound( ignoreNotFound );

	String assocClass = oneToMany.getReferencedEntityName();
	PersistentClass associatedClass = (PersistentClass) persistentClasses.get( assocClass );
	if ( jpaOrderBy != null ) {
		final String orderByFragment = buildOrderByClauseFromHql(
				jpaOrderBy.value(),
				associatedClass,
				collection.getRole()
		);
		if ( StringHelper.isNotEmpty( orderByFragment ) ) {
			collection.setOrderBy( orderByFragment );
		}
	}

	if ( mappings == null ) {
		throw new AssertionFailure(
				"CollectionSecondPass for oneToMany should not be called with null mappings"
		);
	}
	Map<String, Join> joins = mappings.getJoins( assocClass );
	if ( associatedClass == null ) {
		throw new MappingException(
				"Association references unmapped class: " + assocClass
		);
	}
	oneToMany.setAssociatedClass( associatedClass );
	for (Ejb3JoinColumn column : fkJoinColumns) {
		column.setPersistentClass( associatedClass, joins, inheritanceStatePerClass );
		column.setJoins( joins );
		collection.setCollectionTable( column.getTable() );
	}
	if ( debugEnabled ) {
		LOG.debugf( "Mapping collection: %s -> %s", collection.getRole(), collection.getCollectionTable().getName() );
	}
	bindFilters( false );
	bindCollectionSecondPass( collection, null, fkJoinColumns, cascadeDeleteEnabled, property, mappings );
	if ( !collection.isInverse()
			&& !collection.getKey().isNullable() ) {
		// for non-inverse one-to-many, with a not-null fk, add a backref!
		String entityName = oneToMany.getReferencedEntityName();
		PersistentClass referenced = mappings.getClass( entityName );
		Backref prop = new Backref();
		prop.setName( '_' + fkJoinColumns[0].getPropertyName() + '_' + fkJoinColumns[0].getLogicalColumnName() + "Backref" );
		prop.setUpdateable( false );
		prop.setSelectable( false );
		prop.setCollectionRole( collection.getRole() );
		prop.setEntityName( collection.getOwner().getEntityName() );
		prop.setValue( collection.getKey() );
		referenced.addProperty( prop );
	}
}
 
Example 39
Project: lemon   File: BpmMailTemplate.java   View source code 4 votes vote down vote up
/** @return . */
@OneToMany(fetch = FetchType.LAZY, mappedBy = "bpmMailTemplate")
public Set<BpmConfNotice> getBpmConfNotices() {
    return this.bpmConfNotices;
}
 
Example 40
Project: lemon   File: BpmConfBase.java   View source code 4 votes vote down vote up
/** @return . */
@OneToMany(fetch = FetchType.LAZY, mappedBy = "bpmConfBase")
public Set<BpmConfNode> getBpmConfNodes() {
    return this.bpmConfNodes;
}