下面列出了javax.persistence.Embeddable#javax.persistence.MapKeyColumn 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void getMapKeyColumn(List<Annotation> annotationList, Element element) {
Element subelement = element != null ? element.element( "map-key-column" ) : null;
if ( subelement != null ) {
AnnotationDescriptor ad = new AnnotationDescriptor( MapKeyColumn.class );
copyStringAttribute( ad, subelement, "name", false );
copyBooleanAttribute( ad, subelement, "unique" );
copyBooleanAttribute( ad, subelement, "nullable" );
copyBooleanAttribute( ad, subelement, "insertable" );
copyBooleanAttribute( ad, subelement, "updatable" );
copyStringAttribute( ad, subelement, "column-definition", false );
copyStringAttribute( ad, subelement, "table", false );
copyIntegerAttribute( ad, subelement, "length" );
copyIntegerAttribute( ad, subelement, "precision" );
copyIntegerAttribute( ad, subelement, "scale" );
annotationList.add( AnnotationFactory.create( ad ) );
}
}
private void makeOneToManyMapKeyColumnNullableIfNotInProperty(
final XProperty property) {
final org.hibernate.mapping.Map map = (org.hibernate.mapping.Map) this.collection;
if ( map.isOneToMany() &&
property.isAnnotationPresent( MapKeyColumn.class ) ) {
final Value indexValue = map.getIndex();
if ( indexValue.getColumnSpan() != 1 ) {
throw new AssertionFailure( "Map key mapped by @MapKeyColumn does not have 1 column" );
}
final Selectable selectable = indexValue.getColumnIterator().next();
if ( selectable.isFormula() ) {
throw new AssertionFailure( "Map key mapped by @MapKeyColumn is a Formula" );
}
Column column = (Column) map.getIndex().getColumnIterator().next();
if ( !column.isNullable() ) {
final PersistentClass persistentClass = ( ( OneToMany ) map.getElement() ).getAssociatedClass();
// check if the index column has been mapped by the associated entity to a property;
// @MapKeyColumn only maps a column to the primary table for the one-to-many, so we only
// need to check "un-joined" properties.
if ( !propertyIteratorContainsColumn( persistentClass.getUnjoinedPropertyIterator(), column ) ) {
// The index column is not mapped to an associated entity property so we can
// safely make the index column nullable.
column.setNullable( true );
}
}
}
}
@ElementCollection
@MapKeyColumn(name = "parameters_idx")
@Column(name = "parameters_elt")
@CollectionTable(name = "info_parameters")
public Map<String, String> getParameters() {
return parameters;
}
/**
* Returns all set parameters of the job.
*
* @return the job parameters
*/
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "MCRJobParameter", joinColumns = @JoinColumn(name = "jobID"))
@MapKeyColumn(name = "paramKey", length = 128)
@Column(name = "paramValue", length = 255)
public Map<String, String> getParameters() {
return parameters;
}
@ElementCollection(fetch = FetchType.EAGER)
@MapKeyColumn(name="attribute", insertable=false,updatable=false)
@Column(name="value")
@CollectionTable(name="timing_location_input_attributes", [email protected](name="tli_id"))
@OrderColumn(name = "index_id")
public Map<String, String> getAttributes() {
//System.out.println("TLI.getAttributes called, returning " + attributes.size() + " attributes");
return attributes;
}
@ElementCollection(fetch = FetchType.EAGER)
@MapKeyColumn(name="chip", insertable=false,updatable=false)
@Column(name="bib")
@CollectionTable(name="bib2chipmap", [email protected](name="bib2chip_id"))
public Map<String, String> getChip2BibMap() {
//System.out.println("TLI.getAttributes called, returning " + attributes.size() + " attributes");
return chip2bibMap;
}
@ElementCollection(fetch = FetchType.EAGER)
@MapKeyColumn(name="attribute_id")
@Column(name="attribute_value")
@CollectionTable(name="participant_attributes", [email protected](name="participant_id"))
public Map<Integer,String> getCustomAttributes(){
return customAttributeMap;
}
@ElementCollection(fetch = FetchType.EAGER)
@MapKeyColumn(name="attribute", insertable=false,updatable=false)
@Column(name="value")
@CollectionTable(name="event_options_attributes", [email protected](name="event_id"))
//@OrderColumn(name = "index_id")
private Map<String, String> getAttributes() {
System.out.println("EventOptions::getAttributes()");
attributes.keySet().forEach(k -> {
System.out.println(" " + k + " -> " + attributes.get(k));
});
return attributes;
}
@ElementCollection(fetch = FetchType.EAGER)
@MapKeyColumn(name="attribute", insertable=false,updatable=false)
@Column(name="value")
@CollectionTable(name="race_awards_attributes", [email protected](name="race_id"))
@OrderColumn(name = "index_id")
private Map<String, String> getAttributes() {
return attributes;
}
@ElementCollection(fetch = FetchType.EAGER)
@MapKeyColumn(name="attribute", insertable=false,updatable=false)
@Column(name="value")
@CollectionTable(name="race_attributes", [email protected](name="race_id"))
private Map<String, String> getAttributes() {
return attributes;
}
@ElementCollection(fetch = FetchType.EAGER)
@MapKeyColumn(name="attribute", insertable=false,updatable=false)
@Column(name="value")
@CollectionTable(name="race_output_attributes", [email protected](name="output_id"))
@OrderColumn(name = "id")
private Map<String, String> getAttributes() {
return attributes;
}
@ElementCollection(fetch = FetchType.EAGER)
@MapKeyColumn(name="split_id", insertable=false,updatable=false)
@Column(name="split_time",nullable=false)
@CollectionTable(name="split_results", [email protected](name="result_id"))
public Map<Integer,Long> getSplitMap(){
return splitMap;
}
public MapKeyColumnDelegator(MapKeyColumn column) {
this.column = column;
}
@ElementCollection(fetch = FetchType.EAGER)
@MapKeyColumn(name = "extraPropName")
public Map<String, String> getExtraProperties() {
return extraProperties;
}
/**
* Get the list of additional client properties
* @return the list of properties
*/
@ElementCollection(fetch = FetchType.EAGER)
@MapKeyColumn(name = "name")
public Map<String, String> getProperties() {
return properties;
}
/**
* Get the list of additional user subject properties
*
* @return the list of properties
*/
@ElementCollection(fetch = FetchType.EAGER)
@MapKeyColumn(name = "name")
public Map<String, String> getProperties() {
return properties;
}
/**
* Gets token parameters
* @return
*/
@ElementCollection(fetch = FetchType.EAGER)
@MapKeyColumn(name = "propName")
public Map<String, String> getParameters() {
return parameters;
}
@ElementCollection(fetch = FetchType.EAGER)
@MapKeyColumn(name = "extraPropName")
public Map<String, String> getExtraProperties() {
return extraProperties;
}