當前位置: 首頁>>代碼示例>>Java>>正文


Java Hibernate類代碼示例

本文整理匯總了Java中org.hibernate.Hibernate的典型用法代碼示例。如果您正苦於以下問題:Java Hibernate類的具體用法?Java Hibernate怎麽用?Java Hibernate使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Hibernate類屬於org.hibernate包,在下文中一共展示了Hibernate類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getComparisonInitialiserForStopEdit

import org.hibernate.Hibernate; //導入依賴的package包/類
@Override
protected ComparisonEntityInitialiser<ItemDefinition> getComparisonInitialiserForStopEdit()
{
	return new ComparisonEntityInitialiser<ItemDefinition>()
	{
		@Override
		public void preUnlink(ItemDefinition t)
		{
			// We suck the big one for misusing hibernate.
			initBundle(t.getName());
			initBundle(t.getDescription());
			t.getItemMetadataRules();
			Hibernate.initialize(t.getWorkflow());
		}
	};
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:17,代碼來源:ItemDefinitionServiceImpl.java

示例2: createBlob

import org.hibernate.Hibernate; //導入依賴的package包/類
/**
	 * Permet de créer un Blob à partir d'un stream sans indiquer/connaître la taille. Fonctionne uniquement avec jdbc4. Une exception est
	 * lancée si jdbc4 n'est pas présent.
	 * 
	 * @param aInputStream
	 * @return
	 */
	public Blob createBlob(InputStream aInputStream) {

		final LobCreator lobCreator = Hibernate.getLobCreator(session);
//		// JDBC4 -> pas besoin de la taille
//		if (lobCreator instanceof ContextualLobCreator) {
//			// Passage de -1 comme taille: De toutes façons cette valeur n'est pas utilisée en jdbc4
//			return lobCreator.createBlob(aInputStream, -1);
//		}
//		else {
			// Fallback JDBC3
			// On récupère le stream pour connaitre la taille
			final ByteArrayOutputStream bos = new ByteArrayOutputStream();
			try {
				IOUtils.copy(aInputStream, bos);
				return lobCreator.createBlob(new ByteArrayInputStream(bos.toByteArray()), bos.size());
			}
			catch (IOException ioe) {
				throw new RuntimeException(ioe);
			}
//		}
	}
 
開發者ID:shared-vd,項目名稱:tipi-engine,代碼行數:29,代碼來源:BlobFactory.java

示例3: findBySSO

import org.hibernate.Hibernate; //導入依賴的package包/類
public AdmUser findBySSO(String email) {
    logger.info("email : {}", email);
    Criteria crit = createEntityCriteria();
    crit.add(Restrictions.eq("email", email));
    AdmUser user = (AdmUser) crit.uniqueResult();
    if (user != null) {
        Hibernate.initialize(user.getUserRoles());
    }
    return user;
}
 
開發者ID:mustafamym,項目名稱:FeedbackCollectionAndMgmtSystem,代碼行數:11,代碼來源:UserDaoImpl.java

示例4: removeProduct

import org.hibernate.Hibernate; //導入依賴的package包/類
/**
 * Remove a product from a collection. The product should stay in the
 * database.
 *
 * @param cid the collection id where remove product.
 * @param pid the product id to remove.
 * @param user unused parameter.
 */
public void removeProduct (final String cid, final Long pid, User user)
{
   Collection collection = read(cid);
   if (collection == null)
   {
      LOGGER.warn("Unknown collection #" + cid);
      return;
   }
   Product product = productDao.read(pid);
   if (product == null)
   {
      LOGGER.warn("Unknown product #" + pid);
      return;
   }

   Hibernate.initialize (collection.getProducts());
   collection.getProducts().remove(product);
   update(collection);

   fireProductRemoved (new DaoEvent<> (collection), product);
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:30,代碼來源:CollectionDao.java

示例5: delete

import org.hibernate.Hibernate; //導入依賴的package包/類
@Override
public void delete ()
{
   Long id = 1L;
   FileScanner element = dao.read (id);
   Set<Collection> collections = element.getCollections ();
   Hibernate.initialize (collections);
   dao.delete (element);

   assertEquals (dao.count (), (howMany () - 1));
   assertNull (dao.read (id));
   for (Collection collection : collections)
   {
      assertNotNull (cdao.read (collection.getUUID ()));
   }
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:17,代碼來源:TestFileScannerDao.java

示例6: delete

import org.hibernate.Hibernate; //導入依賴的package包/類
@Override
@Test (dependsOnMethods = { "read", "create" })
public void delete ()
{
   long id = 1;
   Eviction eviction = dao.read (id);
   Set<Product> ps = eviction.getProducts ();
   Hibernate.initialize (ps);

   dao.delete (eviction);
   assertEquals (dao.count (), (howMany () - 1));
   assertNull (dao.read (id));
   for (Product p : ps)
   {
      assertNotNull (pdao.read (p.getId ()));
   }
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:18,代碼來源:TestEvictionDao.java

示例7: unproxyEntity

import org.hibernate.Hibernate; //導入依賴的package包/類
protected <T> T unproxyEntity(T template) {
    if (template instanceof HibernateProxy) {
        Hibernate.initialize(template);
        template = (T) ((HibernateProxy) template)
                .getHibernateLazyInitializer()
                .getImplementation();
    }
    return template;
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:10,代碼來源:EJBTestBase.java

示例8: getById

import org.hibernate.Hibernate; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public T getById(Long pk) throws SQLException {
	Session session = HibernateUtil.getSessionFactory().openSession();
	T entity = null;

	try {
		session.beginTransaction();
		entity = (T) session.get(getEntityClass(), pk);
		Hibernate.initialize(entity);
		session.getTransaction().commit();

	} catch (HibernateException hibernateException) {
		session.getTransaction().rollback();

		throw new SQLException(hibernateException);

	} finally {
		session.close();
	}

	return entity;
}
 
開發者ID:mrh3nry,項目名稱:Celebino,代碼行數:23,代碼來源:GenericDao.java

示例9: nullSafeGet

import org.hibernate.Hibernate; //導入依賴的package包/類
@Override
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws SQLException
{
	String dbValue = Hibernate.STRING.nullSafeGet(rs, names[0]);
	if( dbValue != null )
	{
		return unescape(dbValue);
	}
	else
	{
		return null;
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:14,代碼來源:HibernateEscapedString.java

示例10: createMappings

import org.hibernate.Hibernate; //導入依賴的package包/類
private EntryCache createMappings(List<MimeEntry> entries)
{
	Map<String, MimeEntry> mappedEntries = new HashMap<String, MimeEntry>();
	Map<String, MimeEntry> mimeEntries = new HashMap<String, MimeEntry>();
	for( MimeEntry mimeEntry : entries )
	{
		Collection<String> extensions = mimeEntry.getExtensions();
		// Load it all up
		Hibernate.initialize(mimeEntry.getAttributes());
		for( String ext : extensions )
		{
			mappedEntries.put(ext, mimeEntry);
		}
		mimeEntries.put(mimeEntry.getType(), mimeEntry);
	}
	return new EntryCache(mappedEntries, mimeEntries);
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:18,代碼來源:MimeTypeServiceImpl.java

示例11: reassociateIfUninitializedProxy

import org.hibernate.Hibernate; //導入依賴的package包/類
@Override
public boolean reassociateIfUninitializedProxy(Object value) throws MappingException {
	if ( value instanceof ElementWrapper ) {
		value = ( (ElementWrapper) value ).getElement();
	}

	if ( !Hibernate.isInitialized( value ) ) {
		final HibernateProxy proxy = (HibernateProxy) value;
		final LazyInitializer li = proxy.getHibernateLazyInitializer();
		reassociateProxy( li, proxy );
		return true;
	}
	else {
		return false;
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:17,代碼來源:StatefulPersistenceContext.java

示例12: set

import org.hibernate.Hibernate; //導入依賴的package包/類
protected void set(PreparedStatement st, Object value, int index, SessionImplementor session) throws SQLException {
	if ( value == null ) {
		st.setNull( index, sqlTypes( null )[0] );
	}
	else {
		byte[] toSet = unWrap( value );
		final boolean useInputStream = session.getFactory().getDialect().useInputStreamToInsertBlob();

		if ( useInputStream ) {
			st.setBinaryStream( index, new ByteArrayInputStream( toSet ), toSet.length );
		}
		else {
			st.setBlob( index, Hibernate.getLobCreator( session ).createBlob( toSet ) );
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:17,代碼來源:ByteArrayBlobType.java

示例13: getOptions

import org.hibernate.Hibernate; //導入依賴的package包/類
private WrapperOptions getOptions(final SessionImplementor session) {
	return new WrapperOptions() {
		public boolean useStreamForLobBinding() {
			return Environment.useStreamsForBinary()
					|| session.getFactory().getDialect().useInputStreamToInsertBlob();
		}

		public LobCreator getLobCreator() {
			return Hibernate.getLobCreator( session );
		}

		public SqlTypeDescriptor remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
			final SqlTypeDescriptor remapped = sqlTypeDescriptor.canBeRemapped()
					? session.getFactory().getDialect().remapSqlTypeDescriptor( sqlTypeDescriptor )
					: sqlTypeDescriptor;
			return remapped == null ? sqlTypeDescriptor : remapped;
		}
	};
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:20,代碼來源:AbstractStandardBasicType.java

示例14: createEcrfFieldStatusEntryDetachedCriteriaMaxId

import org.hibernate.Hibernate; //導入依賴的package包/類
private static DetachedCriteria createEcrfFieldStatusEntryDetachedCriteriaMaxId(org.hibernate.Criteria ecrfFieldStatusEntryCriteria, org.hibernate.Criteria ecrfFieldCriteria,
		org.hibernate.Criteria probandListEntryCriteria,
		ECRFFieldStatusQueue queue, Long probandListEntryId, Long ecrfFieldId) {
	DetachedCriteria subQuery = createEcrfFieldStatusEntryDetachedCriteria(ecrfFieldStatusEntryCriteria, ecrfFieldCriteria, probandListEntryCriteria, probandListEntryId,
			ecrfFieldId);
	if (queue != null) {
		subQuery.add(Restrictions.eq("queue", queue));
		subQuery.setProjection(Projections.max("id"));
	} else {
		ProjectionList proj = Projections.projectionList();
		proj.add(Projections.sqlGroupProjection(
				"max({alias}.id) as maxId",
				"{alias}.queue",
				new String[] { "maxId" },
				new org.hibernate.type.Type[] { Hibernate.LONG }));
		subQuery.setProjection(proj);
	}

	return subQuery;
}
 
開發者ID:phoenixctms,項目名稱:ctsms,代碼行數:21,代碼來源:ECRFFieldStatusEntryDaoImpl.java

示例15: getHomeMunicipalityName

import org.hibernate.Hibernate; //導入依賴的package包/類
@Nonnull
public LocalisedString getHomeMunicipalityName() {
    if (this.homeMunicipality != null) {
        if (!Hibernate.isInitialized(this.homeMunicipality)) {
            try {
                // Referenced row might not exist
                return this.homeMunicipality.getNameLocalisation();
            } catch (UnresolvableObjectException | EntityNotFoundException o) {
                this.homeMunicipality = null;
            }
        } else {
            return this.homeMunicipality.getNameLocalisation();
        }
    }
    return LocalisedString.EMPTY;
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-web,代碼行數:17,代碼來源:Person.java


注:本文中的org.hibernate.Hibernate類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。