private javax.persistence.EnumType getEnumType(ParameterType reader) { javax.persistence.EnumType enumType = null; if ( reader.isPrimaryKey() ) { MapKeyEnumerated enumAnn = getAnnotation( reader.getAnnotationsMethod(), MapKeyEnumerated.class ); if ( enumAnn != null ) { enumType = enumAnn.value(); } } else { Enumerated enumAnn = getAnnotation( reader.getAnnotationsMethod(), Enumerated.class ); if ( enumAnn != null ) { enumType = enumAnn.value(); } } return enumType; }
@Entity(name = "Person") public static class Person { @Id private Long id; @OneToMany(mappedBy = "person", cascade = CascadeType.ALL, orphanRemoval = true) @MapKey(name = "type") @MapKeyEnumerated private Map<PhoneType, Phone> phoneRegister = new HashMap<>(); //Getters and setters are omitted for brevity //end::collections-map-bidirectional-example[] public Person() { } public Person(Long id) { this.id = id; } public Map<PhoneType, Phone> getPhoneRegister() { return phoneRegister; } //tag::collections-map-bidirectional-example[] public void addPhone(Phone phone) { phone.setPerson( this ); phoneRegister.put( phone.getType(), phone ); } }
@Test public void testMapKeyEnumerated() throws Exception { reader = getReader( Entity3.class, "field1", "element-collection.orm9.xml" ); assertAnnotationPresent( ElementCollection.class ); assertAnnotationNotPresent( MapKey.class ); assertAnnotationNotPresent( MapKeyClass.class ); assertAnnotationNotPresent( MapKeyTemporal.class ); assertAnnotationPresent( MapKeyEnumerated.class ); assertAnnotationNotPresent( MapKeyColumn.class ); assertAnnotationNotPresent( MapKeyJoinColumns.class ); assertAnnotationNotPresent( MapKeyJoinColumn.class ); assertEquals( EnumType.STRING, reader.getAnnotation( MapKeyEnumerated.class ).value() ); }
private java.lang.String id; @MapKeyEnumerated( EnumType.STRING ) @MapKeyColumn(name = "social_network") @OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
@Test public void testMapKeyEnumerated() throws Exception { reader = getReader( Entity3.class, "field1", "many-to-many.orm9.xml" ); assertAnnotationPresent( ManyToMany.class ); assertAnnotationNotPresent( MapKey.class ); assertAnnotationNotPresent( MapKeyClass.class ); assertAnnotationNotPresent( MapKeyTemporal.class ); assertAnnotationPresent( MapKeyEnumerated.class ); assertAnnotationNotPresent( MapKeyColumn.class ); assertAnnotationNotPresent( MapKeyJoinColumns.class ); assertAnnotationNotPresent( MapKeyJoinColumn.class ); assertEquals( EnumType.STRING, reader.getAnnotation( MapKeyEnumerated.class ).value() ); }
/** * @author Janario Oliveira */ @Entity @TypeDef(typeClass = LastNumberType.class, defaultForType = LastNumber.class) public class EntityMapEnum { @Id @GeneratedValue int id; @ElementCollection Map<Common, String> ordinalMap = new HashMap<Common, String>(); @ElementCollection @MapKeyEnumerated(EnumType.STRING) Map<Common, String> stringMap = new HashMap<Common, String>(); @ElementCollection @MapKeyType(@Type(type = "org.hibernate.test.annotations.enumerated.custom_types.FirstLetterType")) Map<FirstLetter, String> firstLetterMap = new HashMap<FirstLetter, String>(); @ElementCollection Map<LastNumber, String> lastNumberMap = new HashMap<LastNumber, String>(); @MapKeyEnumerated(EnumType.STRING) @ElementCollection @CollectionTable(name = "overridingMap") @MapKeyColumn(name = "overridingMap_key") Map<LastNumber, String> explicitOverridingImplicitMap = new HashMap<LastNumber, String>(); }
private javax.persistence.EnumType getEnumType(XProperty property) { javax.persistence.EnumType enumType = null; if (key) { MapKeyEnumerated enumAnn = property.getAnnotation( MapKeyEnumerated.class ); if ( enumAnn != null ) { enumType = enumAnn.value(); } } else { Enumerated enumAnn = property.getAnnotation( Enumerated.class ); if ( enumAnn != null ) { enumType = enumAnn.value(); } } return enumType; }
@MapKeyEnumerated(EnumType.STRING) @MapKeyColumn(nullable=false) public Map<Level, String> colorPerLevel = new HashMap<Level,String>();
/** * Handles the {@link MapKeyEnumerated} annotation. * * @param member * the member * @param parsed * the list of annotations parsed * @return the map key value * * @since 2.0.0 */ private EnumType handleMapKeyEnumType(Member member, Set<Class<? extends Annotation>> parsed) { final MapKeyEnumerated annotation = ReflectHelper.getAnnotation(member, MapKeyEnumerated.class); if (annotation != null) { parsed.add(MapKeyEnumerated.class); return annotation.value(); } return null; }
@MapKeyEnumerated(EnumType.STRING) private Map<AddressType, String> addresses = new HashMap<>();
/** * Handles the {@link MapKeyEnumerated} annotation. * * @param member * the member * @param parsed * the list of annotations parsed * @return the map key value * * @since 2.0.0 */ private EnumType handleMapKeyEnumType(Member member, Set<Class<? extends Annotation>> parsed) { final MapKeyEnumerated annotation = ReflectHelper.getAnnotation(member, MapKeyEnumerated.class); if (annotation != null) { parsed.add(MapKeyEnumerated.class); return annotation.value(); } return null; }
/** * Used to store various user's settings, in form of key - value for flexibility. */ @ElementCollection @MapKeyEnumerated(EnumType.STRING) @CollectionTable(name = "SDC_SEDNO_USER_VARPREFS", joinColumns = @JoinColumn(name = "fk_sedno_user_settings")) public Map<SettingName, String> getVariousSettings() { if (variousSettings == null) { variousSettings = new HashMap<SettingName, String>(); } return variousSettings; }
/** * Handles the {@link MapKeyEnumerated} annotation. * * @param member * the member * @param parsed * the list of annotations parsed * @return the map key value * * @since 2.0.0 */ protected EnumType handleMapKeyEnumType(Member member, Set<Class<? extends Annotation>> parsed) { final MapKeyEnumerated annotation = ReflectHelper.getAnnotation(member, MapKeyEnumerated.class); if (annotation != null) { parsed.add(MapKeyEnumerated.class); return annotation.value(); } return null; }
@MapKeyEnumerated(EnumType.STRING) @MapKeyColumn(name = "metadata_type") @JoinTable(name = "TransMemory_Metadata",
/** * Handles the {@link MapKeyEnumerated} annotation. * * @param member * the member * @param parsed * the list of annotations parsed * @return the map key value * * @since 2.0.0 */ protected EnumType handleMapKeyEnumType(Member member, Set<Class<? extends Annotation>> parsed) { final MapKeyEnumerated annotation = ReflectHelper.getAnnotation(member, MapKeyEnumerated.class); if (annotation != null) { parsed.add(MapKeyEnumerated.class); return annotation.value(); } return null; }
@MapKeyClass(HealthType.class) @MapKeyColumn(name = "health", unique = true) @MapKeyEnumerated(EnumType.STRING) @Fetch(FetchMode.SUBSELECT) private Map<HealthType, Integer> items;
/** * Handles the {@link MapKeyEnumerated} annotation. * * @param member * the member * @param parsed * the list of annotations parsed * @return the map key value * * @since 2.0.0 */ private EnumType handleMapKeyEnumType(Member member, Set<Class<? extends Annotation>> parsed) { final MapKeyEnumerated annotation = ReflectHelper.getAnnotation(member, MapKeyEnumerated.class); if (annotation != null) { parsed.add(MapKeyEnumerated.class); return annotation.value(); } return null; }
@JoinTable(name="UM_PARTNERS") @MapKeyColumn(name="PARTNERTYPE") @MapKeyEnumerated(EnumType.STRING) private final Map<PartnerType, TradingPartner> partners;
/** * Handles the {@link MapKeyEnumerated} annotation. * * @param member * the member * @param parsed * the list of annotations parsed * @return the map key value * * @since 2.0.0 */ protected EnumType handleMapKeyEnumType(Member member, Set<Class<? extends Annotation>> parsed) { final MapKeyEnumerated annotation = ReflectHelper.getAnnotation(member, MapKeyEnumerated.class); if (annotation != null) { parsed.add(MapKeyEnumerated.class); return annotation.value(); } return null; }
/** * Parse @MapKeyEnumerated. */ private void parseMapKeyEnumerated(FieldMapping fm, MapKeyEnumerated anno) { String strat = EnumValueHandler.class.getName() + "(StoreOrdinal=" + String.valueOf(anno.value() == EnumType.ORDINAL) + ")"; fm.getKeyMapping().getValueInfo().setStrategy(strat); }