Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8915623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:00:48+00:00 2026-06-15T05:00:48+00:00

I have the following class: @Entity @Table(name=ripa_request) public class ReturningInvoiceRequest implements EntityKey<Long> { public

  • 0

I have the following class:

@Entity
@Table(name="ripa_request")
public class ReturningInvoiceRequest implements EntityKey<Long> {

public enum ReturningInvoiceRequestStatus {
    /**
     * This status means that the products for this request are chosen, but not confirmed at all. 
     */
    WAITING_TO_SEND("Aguardando envio para o fornecedor"),

    /**
     * This status means that the returning request is done but the supplier needs to approve the chosen products. 
     */
    WAITING_FOR_ACCEPTANCE("Aguardando aprovação do fornecedor"),

    /**
     * This status means that the invoice was generated with the returning request products and the products are dispatched.
     */
    INVOICE_DISPATCHED("Nota Fiscal de devolução emitida"), 

    /**
     * This status means that something wrong happened on the returning request process. 
     */
    INVALID("Requisição inválida");

    private String message;

    private ReturningInvoiceRequestStatus(String message) {
        this.message = message;
    }

    /* (non-Javadoc)
     * @see java.lang.Enum#toString()
     */
    @Override
    public String toString() {
        return message;
    }
}

@Id
@GeneratedValue
private Long id;

/**
 * Mapping for the Products associated to this request with related information: Product Invoice's included with chosen count.
 */
@ElementCollection(targetClass=ProductRequestContext.class)
@MapKeyJoinColumn(name="product_id")
@CollectionTable(name="ripa_request_product", joinColumns=@JoinColumn(name="request_id"))
@Columns(columns={@Column(name="invoice_id"), @Column(name="count")})
private Map<Product, Collection<ProductRequestContext>> productCountMap;

@Temporal(TemporalType.TIMESTAMP)
private Date date;

@Enumerated(EnumType.STRING)
private ReturningInvoiceRequestStatus status;


public ReturningInvoiceRequest() {
    this.status = ReturningInvoiceRequestStatus.WAITING_TO_SEND;
}

public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}    

public Collection<Product> getProductList() {
    return this.productCountMap == null ? new ArrayList<Product>() : this.productCountMap.keySet();
}

public void setProductList(Collection<Product> productList) {
    this.productCountMap = new HashMap<>();
    for (Product product : productList) {
        if (product.getInvoiceList() == null || product.getInvoiceList().isEmpty()) {
            setStatus(ReturningInvoiceRequestStatus.INVALID);
            break;
        } else {
            List<ProductRequestContext> productContextList = new ArrayList<>();
            for (Invoice invoice : product.getInvoiceList()) {
                productContextList.add(new ProductRequestContext(invoice.getId(), product.getCount(invoice)));
            }
            this.productCountMap.put(product, productContextList);  
        }
    }
}

public Date getDate() {
    return date;
}

public void setDate(Date date) {
    this.date = date;
}

public ReturningInvoiceRequestStatus getStatus() {
    return status;
}

public void setStatus(ReturningInvoiceRequestStatus status) {
    this.status = status;
}

/**
 * Return the Invoice associated to the informed Product of this request
 * @param product Product business entity
 * @return <code>Invoice</code> Invoice business entity
 */
public Invoice getInvoice(Product product) {
    for (Product requestProduct : getProductList()) {
        if (product.equals(requestProduct)) {
            Collection<ProductRequestContext> contextList = (Collection<ProductRequestContext>) this.productCountMap.get(requestProduct);
            for (ProductRequestContext context : contextList) {
                Long invoiceID = context.getRequestInvoiceID();
                for (Invoice reqInvoice : requestProduct.getInvoiceList()) {
                    if (invoiceID.equals(reqInvoice.getId())) {
                        return reqInvoice;
                    }
                }
            }
        }
    }
    return null;
}

/**
 * Return the quantity of the informed Product selected for this request.
 * @param product Product business entity
 * @return
 */
public Integer getCount(Product product) {
    for (Product requestProduct : getProductList()) {
        if (product.equals(requestProduct)) {
            Collection<ProductRequestContext> contextList = (Collection<ProductRequestContext>) this.productCountMap.get(requestProduct);
            for (ProductRequestContext context : contextList) {
                Long invoiceID = context.getRequestInvoiceID();
                for (Invoice reqInvoice : requestProduct.getInvoiceList()) {
                    if (invoiceID.equals(reqInvoice.getId())) {
                        return context.getRequestCount();
                    }
                }
            }
        }
    }
    return null;
}    


/* (non-Javadoc)
 * @see br.com.mls.eanf.entity.ifc.EntityKey#getKey()
 */
public Long getKey() {
    return id;
}

/* (non-Javadoc)
 * @see java.lang.Object#hashCode()
 */
@Override
public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((id == null) ? 0 : id.hashCode());
    return result;
}

/* (non-Javadoc)
 * @see java.lang.Object#equals(java.lang.Object)
 */
@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    ReturningInvoiceRequest other = (ReturningInvoiceRequest) obj;
    if (id == null) {
        if (other.id != null)
            return false;
    } else if (!id.equals(other.id))
        return false;
    return true;
}

/* (non-Javadoc)
 * @see java.lang.Object#toString()
 */
@Override
public String toString() {
    return this.id == null ? super.toString() : this.id.toString();
}



@Embeddable
public static class ProductRequestContext {
    /**
     * Sequence identifier for the Invoice registry on this context.
     */
    @Column(name="invoice_id")
    private long requestInvoiceID;

    @Column(name="count")
    private int requestCount;

    public ProductRequestContext() {
    }

    ProductRequestContext(Long invoiceID, Integer count) {
        this.requestInvoiceID = invoiceID;
        this.requestCount = count;
    }

    public Long getRequestInvoiceID() {
        return requestInvoiceID;
    }

    public void setRequestInvoiceID(Long invoiceID) {
        this.requestInvoiceID = invoiceID;
    }

    public int getRequestCount() {
        return requestCount;
    }

    public void setRequestCount(int count) {
        this.requestCount = count;
    }
}

}

The problem occurs on the mapping relationship with a collection of elements, during the insertion of the ReturningInvoiceRequest entity (by the persit method of EntityManager):

javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of br.com.mls.ripa.domain.model.product.ReturningInvoiceRequest$ProductRequestContext.requestCount

On my research I found some information about no support on hibernate for Collections on values of a Map, and also a MultiMap approach on http://blog.xebia.com/2007/10/05/mapping-multimaps-with-hibernate/, but I don’t know if it will resolve my problem

I also tried to suppress the Collection value using Multimap class from Google Collections, and also doesn’t work because it doesn’t extends java.util.Map, which is the one that hibernate understand, and apache-collections MultiMap doesn’t have support to Generics, which is necessary for Hibernate mappings

I’m using Hibernate 3.6.9, but on version 4.1.8 the error still happen.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:00:49+00:00Added an answer on June 15, 2026 at 5:00 am

    The solution I found was use a list of ProductRequestContext:

    @ElementCollection
    @CollectionTable(name="ripa_request_product", joinColumns=@JoinColumn(name="request_id"))
    @Columns(columns={@Column(name="product_id"), @Column(name="invoice_id"), @Column(name="count")})
    private List<ProductRequestContext> productCountList
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following mapping: @Entity @Table(name = Prequalifications) public class Prequalification implements Serializable
I have this code @Entity @Table(name = picture) public class Picture implements Serializable {
Suppose I have the following entities: @Entity @Table(name = A) public class A implements
I have the following (simplified) Hibernate entities: @Entity @Table(name = package) public class Package
I have the following inner class: @Entity @Table(name = SATTET0) public class SATTET0Key {
I have the following JPA (2.0.2) entities: Employee @Entity @Table(name = T_EMPLOYEE) public class
I have the following class: @Entity @Table(name = USERS) public class User { private
I have the following property defined: @Entity @Table(name = person) public class Person extends
I have the following two entities: Person.java: @Entity @Table(name=PERSON) public class Person { @Id
i have the following entity relationship: SideA: @Entity @Table(name = SideA) public class SideA

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.