1

I have the next database schema:

CREATE TABLE A (id INTEGER);
CREATE TABLE Single_Values (fk_a INTEGER, fk_b INTEGER, value VARCHAR(255));
CREATE TABLE List_Values (fk_a INTEGER, fk_b INTEGER, value VARCHAR(255));
CREATE TABLE B (id INTEGER, name VARCHAR(255));

And i have next object model (schematic):

class B{
    Integer id;
    String name;
}

class SingleValue extends B{
    String value;
}

class ListValues extends B{
    List<String> values;
}

class A{
    Integer id;
    Map<Integer, SingleValue> singleMap;
    Map<Integer, ListValues> listMap;
}

I made next ​​a mapping to the single value's map:

<class name="B">
   <id name="id"/>
   <property name="name"/>
   <joined-subclass name="SingleValue">
       <key column="fk_b"/>
       <property name="value"/>
   </joined-subclass>
</class>
<class name="A">
    <id name="id"/>
    <map name="singleMap" table="Single_Values">
        <key column="fk_a"/>
        <map-key column="fk_b"/>
        <one-to-many class="B"/>
    </map>
</class>

And I stucked with the mapping of listMap. Any help with mapping this will be appreciated.

1 Answer 1

1

Do not use Maps, use Lists. If you want to look up Map-style either use a query or build a temporary map after getting the list from the database. Also, @annotations would make your life more easy?

Sign up to request clarification or add additional context in comments.

2 Comments

Why does Lists better, then Maps? What is temporary map in terms of hibernate? Or it is just good practice for that? PS. I cant using @annotation, because code style. :(
It is more that Lists are supported, but Maps are not! The primary key should be part of the object database table, not somehow present in a Map within another object. There is no special hibernate function. You could revise your code style, everyone are using annotations these days.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.