org.hibernate.type.ManyToOneType Java Examples

The following examples show how to use org.hibernate.type.ManyToOneType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExtendedTimeQueries.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
public List<ExtendedTime> getEntriesForAss(AssessmentBaseIfc ass) {
    log.debug("getEntriesForAss " + ass.getAssessmentBaseId());

    try {
        HibernateCallback hcb = (Session s) -> {
            Query q = s.getNamedQuery(QUERY_GET_ENTRIES_FOR_ASSESSMENT);
            q.setParameter(ASSESSMENT_ID, ass, new ManyToOneType(null, "org.sakaiproject.tool.assessment.data.dao.assessment.AssessmentBaseData"));
            return q.list();
        };
        return (List<ExtendedTime>) getHibernateTemplate().execute(hcb);
    } catch (DataAccessException e) {
        log.error("Failed to get Extended TimeEntries for Assessment: " + ass.getAssessmentBaseId(), e);
        return null;
    }
}
 
Example #2
Source File: ExtendedTimeQueries.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
public List<ExtendedTime> getEntriesForPub(PublishedAssessmentIfc pub) {
    log.debug("getEntriesForPub " + pub.getPublishedAssessmentId());

    try {
        HibernateCallback hcb = (Session s) -> {
            Query q = s.getNamedQuery(QUERY_GET_ENTRIES_FOR_PUBLISHED);
            q.setParameter(PUBLISHED_ID, pub, new ManyToOneType(null, "org.sakaiproject.tool.assessment.data.dao.assessment.PublishedAssessmentData"));
            return q.list();
        };

        return (List<ExtendedTime>) getHibernateTemplate().execute(hcb);
    } catch (DataAccessException e) {
        log.error("Failed to get Extended Time Entries for Published Assessment: " + pub.getPublishedAssessmentId(), e);
        return null;
    }
}
 
Example #3
Source File: ExtendedTimeQueries.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private ExtendedTime getPubAndX(final String query, final PublishedAssessmentIfc pub, final String secondParam, final String secondParamValue) {
    try{
        HibernateCallback hcb = (Session s) -> {
            Query q = s.getNamedQuery(query);
            q.setParameter(PUBLISHED_ID, pub, new ManyToOneType(null, "org.sakaiproject.tool.assessment.data.dao.assessment.PublishedAssessmentData"));
            q.setParameter(secondParam, secondParamValue, new StringType());
            return q.uniqueResult();
        };

        return (ExtendedTime) getHibernateTemplate().execute(hcb);
    } catch (DataAccessException e) {
        log.error("Failed to get extended time for pub: " + pub.getPublishedAssessmentId() + " and user/group: " + secondParamValue, e);
        return null;
    }
}
 
Example #4
Source File: ExtendedTimeQueries.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
public List<ExtendedTime> getEntriesForAss(AssessmentBaseIfc ass) {
    log.debug("getEntriesForAss " + ass.getAssessmentBaseId());

    try {
        HibernateCallback hcb = (Session s) -> {
            Query q = s.getNamedQuery(QUERY_GET_ENTRIES_FOR_ASSESSMENT);
            q.setParameter(ASSESSMENT_ID, ass, new ManyToOneType(null, "org.sakaiproject.tool.assessment.data.dao.assessment.AssessmentBaseData"));
            return q.list();
        };
        return (List<ExtendedTime>) getHibernateTemplate().execute(hcb);
    } catch (DataAccessException e) {
        log.error("Failed to get Extended TimeEntries for Assessment: " + ass.getAssessmentBaseId(), e);
        return null;
    }
}
 
Example #5
Source File: ExtendedTimeQueries.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
public List<ExtendedTime> getEntriesForPub(PublishedAssessmentIfc pub) {
    log.debug("getEntriesForPub " + pub.getPublishedAssessmentId());

    try {
        HibernateCallback hcb = (Session s) -> {
            Query q = s.getNamedQuery(QUERY_GET_ENTRIES_FOR_PUBLISHED);
            q.setParameter(PUBLISHED_ID, pub, new ManyToOneType(null, "org.sakaiproject.tool.assessment.data.dao.assessment.PublishedAssessmentData"));
            return q.list();
        };

        return (List<ExtendedTime>) getHibernateTemplate().execute(hcb);
    } catch (DataAccessException e) {
        log.error("Failed to get Extended Time Entries for Published Assessment: " + pub.getPublishedAssessmentId(), e);
        return null;
    }
}
 
Example #6
Source File: ExtendedTimeQueries.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private ExtendedTime getPubAndX(final String query, final PublishedAssessmentIfc pub, final String secondParam, final String secondParamValue) {
    try{
        HibernateCallback hcb = (Session s) -> {
            Query q = s.getNamedQuery(query);
            q.setParameter(PUBLISHED_ID, pub, new ManyToOneType(null, "org.sakaiproject.tool.assessment.data.dao.assessment.PublishedAssessmentData"));
            q.setParameter(secondParam, secondParamValue, new StringType());
            return q.uniqueResult();
        };

        return (ExtendedTime) getHibernateTemplate().execute(hcb);
    } catch (DataAccessException e) {
        log.error("Failed to get extended time for pub: " + pub.getPublishedAssessmentId() + " and user/group: " + secondParamValue, e);
        return null;
    }
}
 
Example #7
Source File: HibernateEntityMapper.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Construct a entity collection.
 *
 * @param parentMetadata parent meta data
 * @param childMetadata child meta data
 * @param parent parent object
 * @param objects child objects
 */
public HibernateEntityCollection(ClassMetadata parentMetadata, ClassMetadata childMetadata, Object parent,
		Collection<?> objects) {
	this.objects = objects;
	int i = 0;
	for (Type type : childMetadata.getPropertyTypes()) {
		if (type instanceof ManyToOneType) {
			ManyToOneType mto = (ManyToOneType) type;
			if (mto.getAssociatedEntityName().equals(parentMetadata.getEntityName())) {
				parentName = childMetadata.getPropertyNames()[i];
			}
		}
		i++;
	}
	this.metadata = childMetadata;
	this.parent = parent;
}
 
Example #8
Source File: ASTParserLoadingTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testSelectClauseImplicitJoin() {
	Session s = openSession();
	Transaction t = s.beginTransaction();
	Zoo zoo = new Zoo();
	zoo.setName("The Zoo");
	zoo.setMammals( new HashMap() );
	zoo.setAnimals( new HashMap() );
	Mammal plat = new Mammal();
	plat.setBodyWeight( 11f );
	plat.setDescription( "Platypus" );
	plat.setZoo(zoo);
	plat.setSerialNumber("plat123");
	zoo.getMammals().put("Platypus", plat);
	zoo.getAnimals().put("plat123", plat);
	s.persist( plat );
	s.persist(zoo);
	s.flush();
	s.clear();
	Query q = s.createQuery("select distinct a.zoo from Animal a where a.zoo is not null");
	Type type = q.getReturnTypes()[0];
	assertTrue( type instanceof ManyToOneType );
	assertEquals( ( (ManyToOneType) type ).getAssociatedEntityName(), "org.hibernate.test.hql.Zoo" );
	zoo = (Zoo) q.list().get(0);
	assertEquals( zoo.getMammals().size(), 1 );
	assertEquals( zoo.getAnimals().size(), 1 );
	s.clear();
	s.delete(plat);
	s.delete(zoo);
	t.commit();
	s.close();
}
 
Example #9
Source File: ASTParserLoadingTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testSelectClauseImplicitJoinWithIterate() {
	Session s = openSession();
	Transaction t = s.beginTransaction();
	Zoo zoo = new Zoo();
	zoo.setName("The Zoo");
	zoo.setMammals( new HashMap() );
	zoo.setAnimals( new HashMap() );
	Mammal plat = new Mammal();
	plat.setBodyWeight( 11f );
	plat.setDescription( "Platypus" );
	plat.setZoo(zoo);
	plat.setSerialNumber("plat123");
	zoo.getMammals().put("Platypus", plat);
	zoo.getAnimals().put("plat123", plat);
	s.persist( plat );
	s.persist(zoo);
	s.flush();
	s.clear();
	Query q = s.createQuery("select distinct a.zoo from Animal a where a.zoo is not null");
	Type type = q.getReturnTypes()[0];
	assertTrue( type instanceof ManyToOneType );
	assertEquals( ( (ManyToOneType) type ).getAssociatedEntityName(), "org.hibernate.test.hql.Zoo" );
	zoo = (Zoo) q
		.iterate().next();
	assertEquals( zoo.getMammals().size(), 1 );
	assertEquals( zoo.getAnimals().size(), 1 );
	s.clear();
	s.delete(plat);
	s.delete(zoo);
	t.commit();
	s.close();
}
 
Example #10
Source File: Hibernate.java    From cacheonix-core with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * A Hibernate persistent object (entity) type.
 *
 * @param persistentClass a mapped entity class
 */
public static Type entity(Class persistentClass) {
	// not really a many-to-one association *necessarily*
	return new ManyToOneType( persistentClass.getName() );
}
 
Example #11
Source File: Hibernate.java    From cacheonix-core with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * A Hibernate persistent object (entity) type.
 *
 * @param entityName a mapped entity class
 */
public static Type entity(String entityName) {
	// not really a many-to-one association *necessarily*
	return new ManyToOneType( entityName );
}