JBoss Community

Re: Entity hashCode and equals overriding

created by fabio valsecchi in EJB3 Development - View the full discussion

This is my Cart Entity class:

 

-----------------------------------------------------------------

@Entity

@Table(name = "carts")

public class Cart implements Serializable {

private static final long serialVersionUID = 3L;

 

          public Cart() {

        super();

    }

 

@Id

    private String username;

@ElementCollection

    @CollectionTable(name="cartsbooks", joinColumns=@JoinColumn(name="username"))

    @Column(name="quantity")

    @MapKeyJoinColumn(name="isbn", referencedColumnName="isbn")

    private Map<Book,Integer> articles;

private float bill;

 

          public String getUsername() {

  return username;

          }

          public void setUsername(String username) {

                    this.username = username;

          }

          public Map<Book,Integer> getArticles() {

  return articles;

          }

          public void setArticles(Map<Book,Integer> articles) {

                    this.articles = articles;

          }

          public float getBill() {

  return bill;

          }

          public void setBill(float bill) {

                    this.bill = bill;

          }

}

-----------------------------------------------------------------

 

As you can see the getArticles() method returns a HashMap<Book, Integer>, so the subsequent call get(book) should return an Integer value.

 

Thank you!

Reply to this message by going to Community

Start a new discussion in EJB3 Development at Community