using enum list as parameter in HQL query

using enum list as parameter in HQL query

By : user2955941
Date : November 22 2020, 10:48 AM
it should still fix some issue I have an entity called Band with a attribute List genres, Genres is a ENUM with the following values: ALTERNATIVE_ROCK("Alternative Rock"), CLASSIC_ROCK("Classic Rock"), HARD_ROCK("Hard Rock"), HEAVY_METAL("Heavy Metal"),PROGRESSIVE_ROCK("Progressive Rock"); , This works for Hibernate 4
code :
    Query q = s
            .createQuery("SELECT b FROM Q27715453$Band b JOIN b.genres g WHERE g IN (:genres)");
    q.setParameterList("genres", Arrays.asList(Genres.ROCK, Genres.CLASSIC));

Share : facebook icon twitter icon
generic Enum.valueOf method : Enum class in parameter and return Enum item

generic Enum.valueOf method : Enum class in parameter and return Enum item

By : user2569979
Date : March 29 2020, 07:55 AM
This might help you Why implement your own, when you can use Java's own implementation for this?
code :
 YourEnum yourEnum = Enum.valueOf(YourEnum.class, value);
private static <E extends Enum<E>> E getEnum(Class<E> enumClass, String name){
    try {
        return Enum.valueOf(enumClass, name);
    } catch(IllegalArgumentException e) {
        return null;
getEnum(Enum1.class, "A")
Swagger: Reusing an enum definition as query parameter

Swagger: Reusing an enum definition as query parameter

By : Joshua Hurtado
Date : March 29 2020, 07:55 AM
I wish this help you This is possible in OpenAPI 3.0. All parameters now use a schema, and, by extension, can $ref the schemas.
code :
openapi: 3.0.0
        - in: query
          name: action
            $ref: '#/components/schemas/OperationType'

      type: string
        - registration
        - renewal
Swift enum function with string parameter calling with a parameter of the enum class

Swift enum function with string parameter calling with a parameter of the enum class

By : Niranjan Babu
Date : March 29 2020, 07:55 AM
like below fixes the issue I have played around with many variants of doing this over the last couple of years and have settled on the below. It is similar to @rmaddy's version but the rawValue of the enum is a String so that it is easy to convert back and forth between the name and the enum.
I then have static var's for the actual colours themselves. This allows me to refer to the colours in a similar way to UIColor
code :
view.backgroundColor = Palette.blueColor
view.backgroundColor = Palette.colorNamed("blue")
enum Palette : String
    case white
    case orange
    case red
    case pink
    case purple
    case blue

    static func color( named:String) -> UIColor?
        switch named
           case white.rawValue : return whiteColor
           case orange.rawValue : return orangeColor
           case red.rawValue : return redColor
           case pink.rawValue : return pinkColor
           case purple.rawValue : return purpleColor
           case blue.rawValue : return blueColor
           default : return nil

    static let whiteColor = color( withHex:0xffffff)
    static let orangeColor = color( withHex:0xfc622f)
    static let redColor = color( withHex:0xdd202b)
    static let pinkColor = color( withHex:0xff2f7e)
    static let purpleColor = color( withHex:0x9166e6)
    static let blueColor = color( withHex:0x049edd)

extension UIColor
    convenience init( withHexAlpha hex:UInt32)
        let red   = CGFloat((hex >> 24) & 0xff) / 255.0
        let green = CGFloat((hex >> 16) & 0xff) / 255.0
        let blue  = CGFloat((hex >>  8) & 0xff) / 255.0
        let alpha = CGFloat((hex >>  0) & 0xff) / 255.0

        self.init( red:red, green:green, blue:blue, alpha:alpha)

    convenience init( withHex hex:UInt32)
       self.init( withHexAlpha:(hex << 8) | 0xff)
Moshi Custom Adapter for generic List<T:Enum> returns List<List<T:Enum>> instead of List<T:Enum>

Moshi Custom Adapter for generic List<T:Enum> returns List<List<T:Enum>> instead of List<T:Enum>

By : Paul Sop
Date : March 29 2020, 07:55 AM
Hope that helps (Also opened an issue here: https://github.com/square/moshi/issues/768 but was asked to open also a stackoverflow question) I am writing a generic adapter to convert a json-string with lists of enum values. The standard-adapter for enums throws an exception when the list contains an enum-value that is not available. I want to create an adapter that simply skips unknown enum values instead of throwing an exception. I succeeded partially, but for some reason, the object that was converted was not a List but instead a List>. , Register your adapter as handling List, not Tags.
code :
.add(Types.newParameterizedType(List::class.java, Tags::class.java),
override fun fromJson(jsonReader: JsonReader): List<T> {
  val list = ArrayList<T>()
    val jsonNameValue = jsonReader.nextString()
    val entry = jsonNameToEnum[jsonNameValue]
    if(entry!= null){
  return list
class SkipNotFoundEnumInEnumListAdapter<T : Enum<T>>(enumType: Class<T>) : JsonAdapter<List<T>>() {
  private val nameStrings: Array<String>
  private val constants: Array<T>
  private val options: JsonReader.Options

  init {
    try {
      constants = enumType.enumConstants
      nameStrings = Array(constants.size) {
        val constant = constants[it]
        val annotation = enumType.getField(constant.name).getAnnotation(Json::class.java)
        annotation?.name ?: constant.name
      options = JsonReader.Options.of(*nameStrings)
    } catch (e: NoSuchFieldException) {
      throw AssertionError("Missing field in " + enumType.name, e)


  override fun fromJson(reader: JsonReader): List<T> {
    val list = mutableListOf<T>()
    while (reader.hasNext()) {
      val index = reader.selectString(options)
      if (index != -1) {
        list += constants[index]
      } else {
    return list

  override fun toJson(writer: JsonWriter, value: List<T>?) {
    if (value == null) {
      throw IllegalArgumentException("Wrap in .nullSafe()")
    for (i in value.indices) {
Hibernate Query using Enum as Parameter

Hibernate Query using Enum as Parameter

By : Laxman Prasad
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further ...ok - figured it out. In case anyone else is confused, here is what I discovered. It seems that by default, the table is created using the ordinal value (in my case CurrencyType.ordinal()) so the column ends up looking like CURRENCY INTEGER NOT NULL when the table is created.
This is less than ideal as if I change the Enum type (i.e. the order of the values), this will break everything. The good news is I can force it to save the String value (CurrencyType.name()) by adding a @Enumerated(EnumType.STRING) to the method, so it will look like:
Related Posts Related Posts :
  • Passing HttpServletResponse in Spring Boot controller method
  • Failed to load libraries: [netty_tcnative_linux_arm_32, netty_tcnative_linux_arm_32_fedora, netty_tcnative_arm_32, netty
  • How to build a small documents storage?
  • Getting pixel position of a text in an image
  • How do I get a list of Methods called from a Class in Eclipse IDE?
  • Convert string to day of week (not exact date)
  • Unable to understand how rounding is working for decimal digits (Java)
  • How to avoid java.lang.NoSuchMethodError: org.apache.poi.util.IOUtils.copy(Ljava/io/InputStream;Ljava/io/OutputStream;)
  • JTable Renderer not working with RowSorter?
  • From java.util.concurrent.Future<T> to play.libs.F.Promise<T>: How to do that in Java?
  • jUnit tests work in Eclipse, but fail in ant - java.lang.RuntimeException: Stub
  • How do i add a tooltip to existing gwt Textbox?
  • actor replying to non-actor
  • Google Cloud Messaging - server connection
  • Which classes are unmodifiable and cannot be intrumented and is there a way to bypass it?
  • Java & Jersey 1.17: Custom default response headers
  • Java rounding error
  • Setting custom RejectedExecutionHandler for ThreadPoolExecutor after executing some tasks?
  • Arquillian test class variables lose value
  • java.util.ConcurrentModificationException while inserting in ArrayList
  • How to write generic Java API without method Overloading
  • Java Serialization / Deserialization of an ArrayList works only on first program execution
  • Conway's Game of Life's rules dont apply properly
  • call a java method when Click on a html button without using javascript
  • Why does SSLSocketFactory.createSocket returns a Socket instead of SSLSocket?
  • How to schedule a task in Tomcat
  • compare two pdf files (approach) using java
  • What is the use of allowCoreThreadTimeout( ) in ThreadPoolExecutor?
  • Describe the Strategy Design Pattern in Java?
  • MongoDB too many open connections
  • Issue with generate JAXB classes with value constructors
  • Moving from one frame to another in java swing
  • Get a thread by Id
  • how to open front camera and back camera at same time?
  • Messed up with Java Declaration
  • Extracting chart in EXcel as image using java
  • How to get latitude and longitude in Android phone?
  • Do GC pauses and kill -STOP produce the same behavior?
  • Android HTML.ImageGetter Images resized
  • The way to instantiate map<String, List<String>> in Java
  • Java Making objects move while buttons held
  • Androidx Navigation View - `setNavigationItemSelectedListener` Doesn't Work
  • after compiling code JFrame does not appear
  • Netbeans project, JFrames ran from the main JFrame close all JFrames in project
  • Square Retrofit Client: How to enable/disable followRedirects? How to intercept redirect URL?
  • Java Circular Reference - Can’t Compile
  • Mouse click on specific time JAVA
  • android 4 onCreateDialog return type incompatible when overriding
  • Java Implementation of Oracle's DBMS_UTILITY.GET_HASH_VALUE Function
  • javac cannot be run, and furthermore does not seem installed
  • Function to obtain a thread given its ID
  • Java File path to Executable has spaces
  • Minimum Oracle Java VM heap memory setting?
  • Elegant way to create one of a large number of classes
  • Java fx binding styles
  • Summing weights based on string in large file
  • Android ListView setOnItemClickListener not working
  • How is the Java Bootstrap Classloader loaded?
  • Check object is blank
  • Add image between text in JEditorPane
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org