tags:

views:

19

answers:

0

The title is pretty complicated so I'll try and explain it:

We have products that have several language dependent images of different types. Of each type there may be multiple images in an ordered list.

So, in Java I'd express it like this:

Map<String, Map<Long, List<Image>> images;

Where the key of the first map is the language code and the second is the type id.

The table would look like this:

|product_id|language|type|index|image|
+----------+--------+----+-----+-----+
|         1|en      |   1|    0| img1|
|         1|en      |   1|    1| img2|
|         1|en      |   2|    0| img3|
|         1|de      |   1|    0| img4|
|         1|de      |   1|    1| img5|
|         1|de      |   2|    0| img6|
|         2|en      |   2|    0| img7|

How would you map this?

I'd like to be able to use queries like "... where language='en'" or "... where language='en' and type=2" etc. in order to get all images for one language, one type and maybe even a specific image (i.e. product + language + type + index).

Edit:

As a quick update, we're currently using this workaround:

We have a id class: public class ProductImageEntityId implements Serializable { private static final long serialVersionUID = 1L;

  @Column ( name = "procuct_id" )
  private Long productUid;

  @Column (name = "language")
  private String language;

  @Column (name = "type")
  private Long imageType;

  @Column (name = "index")
  private Long listindex;


  public ProductImageEntityId( Long pProductUid, String pLanguage, Long pImageType, Long pIndex )
  {
    super();
    productUid = pProductUid;
    language = pLanguage;
    imageType = pImageType;
    listindex = pIndex;
  }
  ...
}

This id class is used in the product:

@Entity
public class ProductImageEntity
{
  @EmbeddedId
  private ProductImageEntityId id;
  ...
}

The id class attributes are also added to the entity as read only attributes,
e.g. @Column ( name = "language", insertable = false, updatable = false ).

When we need the Map<String, Map<String, List<ProductImageEntity>>> we build it manually.