本文整理匯總了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());
}
};
}
示例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);
}
// }
}
示例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;
}
示例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);
}
示例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 ()));
}
}
示例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 ()));
}
}
示例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;
}
示例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;
}
示例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;
}
}
示例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);
}
示例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;
}
}
示例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 ) );
}
}
}
示例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;
}
};
}
示例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;
}
示例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;
}