1 package org.hibernate.persister.collection; 3 4 import org.hibernate.MappingException; 5 6 import org.hibernate.QueryException; 7 8 import org.hibernate.persister.entity.PropertyMapping; 9 10 import org.hibernate.type.Type; 11 12 import org.hibernate.util.StringHelper; 13 14 17 public class ElementPropertyMapping implements PropertyMapping { 18 19 private final String [] elementColumns; 20 private final Type type; 21 22 public ElementPropertyMapping(String [] elementColumns, Type type) 23 throws MappingException { 24 this.elementColumns = elementColumns; 25 this.type = type; 26 } 27 28 public Type toType(String propertyName) throws QueryException { 29 if ( propertyName==null || "id".equals(propertyName) ) { 30 return type; 31 } 32 else { 33 throw new QueryException("cannot dereference scalar collection element: " + propertyName); 34 } 35 } 36 37 public String [] toColumns(String alias, String propertyName) throws QueryException { 38 if (propertyName==null || "id".equals(propertyName) ) { 39 return StringHelper.qualify(alias, elementColumns); 40 } 41 else { 42 throw new QueryException("cannot dereference scalar collection element: " + propertyName); 43 } 44 } 45 46 49 public String [] toColumns(String propertyName) throws QueryException, UnsupportedOperationException { 50 throw new UnsupportedOperationException ( "References to collections must be define a SQL alias" ); 51 } 52 53 public Type getType() { 54 return type; 55 } 56 57 } | Popular Tags |