@Entity
public class SalesT {
@Id
@GeneratedValue
private int id;
@OneToOne
private Customer customer;
@OneToMany(targetEntity = Product.class)
private List< Map<Product,Integer> > listProduct;// I want to intialize this
public SalesT() {
}
public SalesT(Customer customer, List<Map<Product, Integer>> product) {
this.customer = customer;
this.listProduct = product;
}
}
I want to Initialize List< Map < Product,Integer>> listProduct attribute of the SalesT Class, How do I initialize it?. I tried Like this
List<Map <Product, Integer>> listProduct = new ArrayList <HashMap <Product, Integer>>();
but it is not working.
Thank you.
If you're using JDK 7, you can simply do,
listProduct = new ArrayList<>();
If JDK < 7,
listProduct = new ArrayList<Map<Product, Integer>>();
You can add maps to above list as follows.
Map<Product,Integer> productMap = new HashMap<Product, Integer>();
productMap.put(new Product(), 1);
productMap.put(new Product(), 2);
listProduct.add(productMap);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With