本文整理汇总了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;
}
示例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" );
}
}
示例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();
}
示例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() );
}
示例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 );
}
}
示例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;
}
示例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();
}
}
示例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();
}
示例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) );
}
}
示例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;
}
示例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;
}
}
}
}
示例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 );
}
}
}
示例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();
}
});
}
示例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);
}
}
示例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();
}
});
}