Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to set scale and precision for BigDecimal field in JPA?

800776Nov 7 2008 — edited Nov 7 2008
Hello!
I'm using JPA with TopLink library and PostgreSQL database server.
I have a class with a BigDecimal field price:
@Entity
public class Price implements Serializable
{
	/**
	 * Цена за единицу услуги.
	 */		
	private BigDecimal price = new BigDecimal(0);

	//...
}
Later in main() function:
//...
Price p = new Price();
BigDecimal bd = new BigDecimal(3.14);	
p.setPrice(bd);
em.persist(p);
//...
bd object has scale = 51 and precision = 52. But JPA maps my field price to a table column of type NUMERIC(38,0). So 3.14 value is stored in database as 3 without fraction part.
Does anybody know why? And how can I control this?
Thank you.

PS: Maybe there is some Annotation which should be applied to my field price?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 5 2008
Added on Nov 7 2008
2 comments
3,425 views