Convert data type from an entity to a Type. Eclipse Oxygen

0

I have a JPA entity from table, which handles BigDecimal variables (Pdvhdr), and I need to convert them to PdvhdrType, to make a query.

The problem is that for example, the variable Change Type, I have to convert it to a String (as shown at the beginning), so that in "Public PdvhdrType () {}", it can be accepted as String and the data displayed. Up there all right.

The problem comes when I try to convert from pdvhdr to pdvhdrtye, using Transfer Object, in another class. Since at the moment of converting "TipoCambioS" to BigDecimal, I get the message "The method valueOf (long) in the type BigDecimal is not applicable for the arguments (String)".

I do not know if I'm fine, since I have another problem, because I can not give value to the variable "private BigDecimal Change Type;", since the data has to grab them from the table of the database, so I would have to find a way for the data of that variable to be saved in "private String TypeChangeS = String.valueOf (ChangeChange);"

    
asked by 10.08.2018 в 23:52
source

1 answer

0

Convert String to BigDecimal

Using the decimalFormat . parse :

public BigDecimal stringToBigDecimal(String strValue) throws ParseException {
    DecimalFormat decimalFormat = new DecimalFormat();
    decimalFormat.setParseBigDecimal(true); //Necesario para que devuelva un objeto BigDecimal

    return (BigDecimal) decimalFormat.parse(strValue);
}
  

I do not know if I'm okay, since I have another problem, because I do not   I can give value to the variable "private BigDecimal TypeChange;" because   you have to grab the data from the table in the database,   that he would have to find a way that the data for that variable,   are saved in "private String TypeChangeS =   String.valueOf (Change Type); "

Is not it good for you using a public "setter" method to access that private variable?

    
answered by 22.08.2018 в 17:16