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


Java HibernateException類代碼示例

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


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

示例1: getSessionFactory

import org.hibernate.HibernateException; //導入依賴的package包/類
public static SessionFactory getSessionFactory() {
    if (null != sessionFactory)
        return sessionFactory;
    
    Configuration configuration = new Configuration();

    String jdbcUrl = "jdbc:mysql://"
            + System.getenv("RDS_HOSTNAME")
            + "/"
            + System.getenv("RDS_DB_NAME");
    
    configuration.setProperty("hibernate.connection.url", jdbcUrl);
    configuration.setProperty("hibernate.connection.username", System.getenv("RDS_USERNAME"));
    configuration.setProperty("hibernate.connection.password", System.getenv("RDS_PASSWORD"));

    configuration.configure();
    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
    try {
        sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    } catch (HibernateException e) {
        System.err.println("Initial SessionFactory creation failed." + e);
        throw new ExceptionInInitializerError(e);
    }
    return sessionFactory;
}
 
開發者ID:arun-gupta,項目名稱:lambda-rds-mysql,代碼行數:26,代碼來源:HibernateUtil.java

示例2: initialize

import org.hibernate.HibernateException; //導入依賴的package包/類
@Override
public void initialize(CreationTimestamp annotation, Class<?> propertyType) {
	if ( java.sql.Date.class.isAssignableFrom( propertyType ) ) {
		generator = new TimestampGenerators.CurrentSqlDateGenerator();
	}
	else if ( Time.class.isAssignableFrom( propertyType ) ) {
		generator = new TimestampGenerators.CurrentSqlTimeGenerator();
	}
	else if ( Timestamp.class.isAssignableFrom( propertyType ) ) {
		generator = new TimestampGenerators.CurrentSqlTimestampGenerator();
	}
	else if ( Date.class.isAssignableFrom( propertyType ) ) {
		generator = new TimestampGenerators.CurrentDateGenerator();
	}
	else if ( Calendar.class.isAssignableFrom( propertyType ) ) {
		generator = new TimestampGenerators.CurrentCalendarGenerator();
	}
	else {
		throw new HibernateException( "Unsupported property type for generator annotation @CreationTimestamp" );
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:22,代碼來源:CreationTimestampGeneration.java

示例3: saveReservation

import org.hibernate.HibernateException; //導入依賴的package包/類
@Override
public void saveReservation(Reservation reservation) {

    try {
        session = dataSourceFactory.getSessionFactory().openSession();
        beginTransactionIfAllowed(session);
        session.save(reservation);
        session.getTransaction().commit();

        logging.setMessage("ReservationDaoImpl -> reservations saved successfully.");

    } catch (HibernateException e) {
        session.getTransaction().rollback();
        logging.setMessage("ReservationDaoImpl Error -> " + e.getLocalizedMessage());
    }
    session.close();

}
 
開發者ID:Coder-ACJHP,項目名稱:Hotel-Properties-Management-System,代碼行數:19,代碼來源:ReservationDaoImpl.java

示例4: wrap

import org.hibernate.HibernateException; //導入依賴的package包/類
@Override
public <X> byte[] wrap(X value, WrapperOptions options) {
	if ( value == null ) {
		return null;
	}
	if ( Byte[].class.isInstance( value ) ) {
		return unwrapBytes( (Byte[]) value );
	}
	if ( byte[].class.isInstance( value ) ) {
		return (byte[]) value;
	}
	if ( InputStream.class.isInstance( value ) ) {
		return DataHelper.extractBytes( (InputStream) value );
	}
	if ( Blob.class.isInstance( value ) || DataHelper.isNClob( value.getClass() ) ) {
		try {
			return DataHelper.extractBytes( ( (Blob) value ).getBinaryStream() );
		}
		catch (SQLException e) {
			throw new HibernateException( "Unable to access lob stream", e );
		}
	}

	throw unknownWrap( value.getClass() );
}
 
開發者ID:hibernate,項目名稱:hibernate-ogm-redis,代碼行數:26,代碼來源:Base64ByteArrayTypeDescriptor.java

示例5: extractSchema

import org.hibernate.HibernateException; //導入依賴的package包/類
private static String extractSchema(String qualifiedName) {
	if ( qualifiedName == null ) {
		return null;
	}
	String[] tokens = qualifiedName.split( SEPARATOR );
	if ( tokens.length == 0 || tokens.length == 1 ) {
		return null;
	}
	else if ( tokens.length == 2 ) {
		// todo - this case needs to be refined w/ help of  DatabaseMetaData (HF)
		return null;
	}
	else if ( tokens.length == 3 ) {
		return tokens[0];
	}
	else {
		throw new HibernateException( "Unable to parse object name: " + qualifiedName );
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:20,代碼來源:ObjectName.java

示例6: preprocessSQL

import org.hibernate.HibernateException; //導入依賴的package包/類
/**
 * Modify the SQL, adding lock hints and comments, if necessary
 */
protected String preprocessSQL(
		String sql,
		QueryParameters parameters,
		Dialect dialect,
		List<AfterLoadAction> afterLoadActions) throws HibernateException {
	sql = applyLocks( sql, parameters, dialect, afterLoadActions );
	
	// Keep this here, rather than moving to Select.  Some Dialects may need the hint to be appended to the very
	// end or beginning of the finalized SQL statement, so wait until everything is processed.
	if ( parameters.getQueryHints() != null && parameters.getQueryHints().size() > 0 ) {
		sql = dialect.getQueryHintString( sql, parameters.getQueryHints() );
	}
	
	return getFactory().getSettings().isCommentsEnabled()
			? prependComment( sql, parameters )
			: sql;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:Loader.java

示例7: testUserCreation

import org.hibernate.HibernateException; //導入依賴的package包/類
public static void testUserCreation() {
	Session session = HibernateUtil.getSession();
	Transaction tx = null;
	
	User newUser = new User("jef", "jeff", "jeff", "jeff", "jeff");
	//SQLIntegrityConstraintViolationException
	try {
		tx = session.beginTransaction();
		session.save(newUser);
		tx.commit();
		System.out.println("User: '" + newUser.getUsername() + "' has been successfully created!");
	} catch (HibernateException he) {
		if (tx != null) {
			tx.rollback();
		}
		System.out.println("User creation failed!");
		he.printStackTrace();
		
	} finally {
		session.close();
	}
}
 
開發者ID:grantleymorrison,項目名稱:FlashBoard,代碼行數:23,代碼來源:Driver2.java

示例8: getDeletes

import org.hibernate.HibernateException; //導入依賴的package包/類
@Override
@SuppressWarnings({"unchecked", "deprecation"})
public Iterator getDeletes(CollectionPersister persister, boolean indexIsFormula) throws HibernateException {
	final Type elementType = persister.getElementType();
	final ArrayList snapshot = (ArrayList) getSnapshot();
	final List elements = element.elements( persister.getElementNodeName() );
	final ArrayList result = new ArrayList();
	for ( int i=0; i<snapshot.size(); i++ ) {
		final Object old = snapshot.get( i );
		if ( i >= elements.size() ) {
			result.add( old );
		}
		else {
			final Element elem = (Element) elements.get( i );
			final Object object = elementType.fromXMLNode( elem, persister.getFactory() );
			if ( elementType.isDirty( old, object, getSession() ) ) {
				result.add( old );
			}
		}
	}
	return result.iterator();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:23,代碼來源:PersistentElementHolder.java

示例9: get

import org.hibernate.HibernateException; //導入依賴的package包/類
public Object get(ResultSet rs, String name) throws HibernateException, SQLException {

		if ( Environment.useStreamsForBinary() ) {

			InputStream inputStream = rs.getBinaryStream(name);

			if (inputStream==null) return toExternalFormat( null ); // is this really necessary?

			ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048);
			byte[] buffer = new byte[2048];

			try {
				while (true) {
					int amountRead = inputStream.read(buffer);
					if (amountRead == -1) {
						break;
					}
					outputStream.write(buffer, 0, amountRead);
				}

				inputStream.close();
				outputStream.close();
			}
			catch (IOException ioe) {
				throw new HibernateException( "IOException occurred reading a binary value", ioe );
			}

			return toExternalFormat( outputStream.toByteArray() );

		}
		else {
			return toExternalFormat( rs.getBytes(name) );
		}
	}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:35,代碼來源:AbstractBynaryType.java

示例10: determineDialect

import org.hibernate.HibernateException; //導入依賴的package包/類
/**
 * Determine the appropriate Dialect to use given the connection.
 *
 * @param resolutionInfoSource Access to DialectResolutionInfo used to resolve the Dialect.
 *
 * @return The appropriate dialect instance.
 *
 * @throws HibernateException No connection given or no resolver could make
 * the determination from the given connection.
 */
private Dialect determineDialect(DialectResolutionInfoSource resolutionInfoSource) {
	if ( resolutionInfoSource == null ) {
		throw new HibernateException( "Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set" );
	}

	final DialectResolutionInfo info = resolutionInfoSource.getDialectResolutionInfo();
	final Dialect dialect = dialectResolver.resolveDialect( info );

	if ( dialect == null ) {
		throw new HibernateException(
				"Unable to determine Dialect to use [name=" + info.getDatabaseName() +
						", majorVersion=" + info.getDatabaseMajorVersion() +
						"]; user must register resolver or explicitly set 'hibernate.dialect'"
		);
	}

	return dialect;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:29,代碼來源:DialectFactoryImpl.java

示例11: getEntityPersister

import org.hibernate.HibernateException; //導入依賴的package包/類
@Override
public EntityPersister getEntityPersister(final String entityName, final Object object) {
	errorIfClosed();
	if (entityName==null) {
		return factory.getEntityPersister( guessEntityName( object ) );
	}
	else {
		// try block is a hack around fact that currently tuplizers are not
		// given the opportunity to resolve a subclass entity name.  this
		// allows the (we assume custom) interceptor the ability to
		// influence this decision if we were not able to based on the
		// given entityName
		try {
			return factory.getEntityPersister( entityName ).getSubclassEntityPersister( object, getFactory() );
		}
		catch( HibernateException e ) {
			try {
				return getEntityPersister( null, object );
			}
			catch( HibernateException e2 ) {
				throw e;
			}
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:26,代碼來源:SessionImpl.java

示例12: isUpdateNecessary

import org.hibernate.HibernateException; //導入依賴的package包/類
/**
 * Performs all necessary checking to determine if an entity needs an SQL update
 * to synchronize its state to the database. Modifies the event by side-effect!
 * Note: this method is quite slow, avoid calling if possible!
 */
protected final boolean isUpdateNecessary(FlushEntityEvent event) throws HibernateException {

	EntityPersister persister = event.getEntityEntry().getPersister();
	Status status = event.getEntityEntry().getStatus();

	if ( !event.isDirtyCheckPossible() ) {
		return true;
	}
	else {

		int[] dirtyProperties = event.getDirtyProperties();
		if ( dirtyProperties != null && dirtyProperties.length != 0 ) {
			return true; //TODO: suck into event class
		}
		else {
			return hasDirtyCollections( event, persister, status );
		}

	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:26,代碼來源:DefaultFlushEntityEventListener.java

示例13: iterate

import org.hibernate.HibernateException; //導入依賴的package包/類
@Override
public Iterator<?> iterate(final String queryString, final Object... values) throws DataAccessException {
	return executeWithNativeSession(new HibernateCallback<Iterator<?>>() {
		@Override
		@SuppressWarnings("unchecked")
		public Iterator<?> doInHibernate(Session session) throws HibernateException {
			Query queryObject = session.createQuery(queryString);
			prepareQuery(queryObject);
			if (values != null) {
				for (int i = 0; i < values.length; i++) {
					queryObject.setParameter(i, values[i]);
				}
			}
			return queryObject.iterate();
		}
	});
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:HibernateTemplate.java

示例14: toByteArray

import org.hibernate.HibernateException; //導入依賴的package包/類
/**
 * Reads a byte array from a {@link Blob}.
 * 
 * @param blob
 *            a {@link Blob} containing data.
 * @return data from {@link Blob} as byte array.
 */
public static byte[] toByteArray(Blob blob) {
    if (blob == null) {
        return null;
    }
    InputStream input = null;
    try {
        input = blob.getBinaryStream();
        return IOUtils.toByteArray(input);
    } catch (Exception e) {
        throw new HibernateException("cannot read from blob", e);
    } finally {
        IOUtils.closeQuietly(input);
    }
}
 
開發者ID:oehf,項目名稱:ipf-flow-manager,代碼行數:22,代碼來源:HibernateUtils.java

示例15: find

import org.hibernate.HibernateException; //導入依賴的package包/類
@Override
public List<?> find(final String queryString, final Object... values) throws DataAccessException {
	return executeWithNativeSession(new HibernateCallback<List<?>>() {
		@Override
		@SuppressWarnings("unchecked")
		public List<?> doInHibernate(Session session) throws HibernateException {
			Query queryObject = session.createQuery(queryString);
			prepareQuery(queryObject);
			if (values != null) {
				for (int i = 0; i < values.length; i++) {
					queryObject.setParameter(i, values[i]);
				}
			}
			return queryObject.list();
		}
	});
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:HibernateTemplate.java


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