3 Replies Latest reply on Nov 3, 2006 4:36 AM by maxandersen

    EJB3 Persistence to HashMap

    javaluva

      Hi,
      Could anyone please point me in the right direction?

      I would like to know if it is somehow possible to map the result of a Query in EJB3 to a HashMap instead of to the various fields of an object.

      Something like: HashMap<String,List<? extends Object>> where the HashMap would be keyed on the column names of the ResultSet and the value of each key, a List of whatever type the values is in for that column.

      Any help appreciated.

        • 1. Re: EJB3 Persistence to HashMap
          clebert.suconic

          Take a look at ejb3_0-pdf-spec-persistence.pdf, section 9.1.25...

          You could use MapKey annotation for that.

          • 2. Re: EJB3 Persistence to HashMap
            javaluva

            Thanks for the reply, but I do not know if this is going to help me too much, I might be wrong, I am fairly new to JPA.

            Let me clarify a bit. My ResultSet from a Callable Statement returns an unknown number of fields, which I cannot specify at design time to map to fields of a POJO.

            The only alternative I can see, is if somehow the ResultSetMetaData for this ResultSet can be used by the ejb Query if have executed to map all fields to various keys of a Map with a List of values for the specific column or a single Object per key if there is only 1 row.

            Is this at all possible?
            Any help always appreciated.

            • 3. Re: EJB3 Persistence to HashMap
              maxandersen

              you should be able to just execute the native sql and you would get an Object[] back.

              If you can use the hibernate api you can look at ResultTransformer API