本文整理汇总了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;
}