hibernate - OneToMany using a Map: Order has items, each item has quantity -


i have design db such have table called item (to sold). when item created 1 of part quantity. plan have table item_qty has item_id , quantity (original quantity shopkeeper has).

now customers see item online , place order. desired design such order can have many items , each item have quantity associated (this quantity coming customer e.g. want buy 2 pens).

i ideally want have order class having: map<item, integer> items; integer field quantity. , corresponding table order_items has (order_id, item_id, requested_qty).

is right way? if not - what's best way this. current code have:

@onetomany(cascade = cascadetype.all, fetch = fetchtype.lazy) @mapkeyjoincolumn(name="id") public map<item, integer> getitem() {     return item; } 

i getting:

caused by: org.hibernate.annotationexception: use of @onetomany or @manytomany targeting unmapped class: com.test.shop.jpa.entity.order.item[java.lang.integer]

many tutorials including hibernate's suggest different use case customer having map of orders mapped orderid:order etc. not case.

please suggest best approach , try best implement.

thanks in advance, mustafa

i don't think possible. structure mapped must entity well. possible define entity holds integer in order provide value.

but maybe have @ @elementcollection. btw. why don't add value item?


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

java - More than one row with the given identifier was found: 1, for class: com.model.Diagnosis -