Java 类org.hibernate.TypeMismatchException 实例源码
项目:lams
文件:BinaryLogicOperatorNode.java
protected final void mutateRowValueConstructorSyntaxesIfNecessary(Type lhsType, Type rhsType) {
// TODO : this really needs to be delayed until after we definitively know all node types
// where this is currently a problem is parameters for which where we cannot unequivocally
// resolve an expected type
SessionFactoryImplementor sessionFactory = getSessionFactoryHelper().getFactory();
if ( lhsType != null && rhsType != null ) {
int lhsColumnSpan = getColumnSpan( lhsType, sessionFactory );
if ( lhsColumnSpan != getColumnSpan( rhsType, sessionFactory ) ) {
throw new TypeMismatchException(
"left and right hand sides of a binary logic operator were incompatibile [" +
lhsType.getName() + " : " + rhsType.getName() + "]"
);
}
if ( lhsColumnSpan > 1 ) {
// for dialects which are known to not support ANSI-SQL row-value-constructor syntax,
// we should mutate the tree.
if ( !sessionFactory.getDialect().supportsRowValueConstructorSyntax() ) {
mutateRowValueConstructorSyntax( lhsColumnSpan );
}
}
}
}
项目:cacheonix-core
文件:BinaryLogicOperatorNode.java
protected final void mutateRowValueConstructorSyntaxesIfNecessary(Type lhsType, Type rhsType) {
// TODO : this really needs to be delayed unitl after we definitively know all node types
// where this is currently a problem is parameters for which where we cannot unequivocally
// resolve an expected type
SessionFactoryImplementor sessionFactory = getSessionFactoryHelper().getFactory();
if ( lhsType != null && rhsType != null ) {
int lhsColumnSpan = lhsType.getColumnSpan( sessionFactory );
if ( lhsColumnSpan != rhsType.getColumnSpan( sessionFactory ) ) {
throw new TypeMismatchException(
"left and right hand sides of a binary logic operator were incompatibile [" +
lhsType.getName() + " : "+ rhsType.getName() + "]"
);
}
if ( lhsColumnSpan > 1 ) {
// for dialects which are known to not support ANSI-SQL row-value-constructor syntax,
// we should mutate the tree.
if ( !sessionFactory.getDialect().supportsRowValueConstructorSyntax() ) {
mutateRowValueConstructorSyntax( lhsColumnSpan );
}
}
}
}
项目:cacheonix-core
文件:ASTParserLoadingTest.java
public void testParameterTypeMismatchFailureExpected() {
Session s = openSession();
s.beginTransaction();
Query query = s.createQuery( "from Animal a where a.description = :nonstring" )
.setParameter( "nonstring", new Integer(1) );
try {
query.list();
fail( "query execution should have failed" );
}
catch( TypeMismatchException tme ) {
// expected behavior
}
s.getTransaction().commit();
s.close();
}
项目:iso21090
文件:EntityPartNameQualifierUserType.java
/**
* @param resultSet resultset object
* @param names names of the columns in the resultset
* @param owner parent object on which the value is to be set
* @return returns Set<EntityPartQualifier> object
* @throws SQLException throws exception when error occurs in accessing the resultSet
*/
public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner)
throws SQLException {
String strEntityPartQualifier = resultSet.getString(names[0]);
if (strEntityPartQualifier == null) {
return null;
}
Set<EntityNamePartQualifier> entityNamePartyQualifierSet = new HashSet();
String[] qualifiers = strEntityPartQualifier.split(",");
for (String enpqVal : qualifiers){
try {
entityNamePartyQualifierSet.add(Enum.valueOf(EntityNamePartQualifier.class, enpqVal));
} catch (IllegalArgumentException e){
throw new TypeMismatchException(e);
}
}
return entityNamePartyQualifierSet;
}
项目:iso21090
文件:UriUserType.java
/**
* @param resultSet resultset object
* @param names names of the columns in the resultset
* @param owner parent object on which the value is to be set
* @return returns URI object
* @throws SQLException throws exception when error occurs in accessing the resultSet
*/
public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner)
throws SQLException {
String strURI = resultSet.getString(names[0]);
URI uri = null;
if (null != strURI) {
try {
uri = new URI(strURI);
} catch (URISyntaxException e) {
throw new TypeMismatchException(e);
}
}
return uri;
}
项目:iso21090
文件:UriUserType.java
/**
* @param value value being copied
* @return copied value
*/
public Object deepCopy(Object value) {
if (value == null) {
return null;
}
try {
return new URI(((URI) value).toString());
} catch (URISyntaxException e) {
throw new TypeMismatchException(e);
}
}
项目:cacheonix-core
文件:DefaultLoadEventListener.java
/**
* Handle the given load event.
*
* @param event The load event to be handled.
* @throws HibernateException
*/
public void onLoad(LoadEvent event, LoadEventListener.LoadType loadType) throws HibernateException {
final SessionImplementor source = event.getSession();
EntityPersister persister;
if ( event.getInstanceToLoad() != null ) {
persister = source.getEntityPersister( null, event.getInstanceToLoad() ); //the load() which takes an entity does not pass an entityName
event.setEntityClassName( event.getInstanceToLoad().getClass().getName() );
}
else {
persister = source.getFactory().getEntityPersister( event.getEntityClassName() );
}
if ( persister == null ) {
throw new HibernateException(
"Unable to locate persister: " +
event.getEntityClassName()
);
}
if ( persister.getIdentifierType().isComponentType() && EntityMode.DOM4J == event.getSession().getEntityMode() ) {
// skip this check for composite-ids relating to dom4j entity-mode;
// alternatively, we could add a check to make sure the incoming id value is
// an instance of Element...
}
else {
Class idClass = persister.getIdentifierType().getReturnedClass();
if ( idClass != null && ! idClass.isInstance( event.getEntityId() ) ) {
throw new TypeMismatchException(
"Provided id of the wrong type. Expected: " + idClass + ", got " + event.getEntityId().getClass()
);
}
}
EntityKey keyToLoad = new EntityKey( event.getEntityId(), persister, source.getEntityMode() );
try {
if ( loadType.isNakedEntityReturned() ) {
//do not return a proxy!
//(this option indicates we are initializing a proxy)
event.setResult( load(event, persister, keyToLoad, loadType) );
}
else {
//return a proxy if appropriate
if ( event.getLockMode() == LockMode.NONE ) {
event.setResult( proxyOrLoad(event, persister, keyToLoad, loadType) );
}
else {
event.setResult( lockAndLoad(event, persister, keyToLoad, loadType, source) );
}
}
}
catch(HibernateException e) {
log.info("Error performing load command", e);
throw e;
}
}