Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can i use BigDecimal as an id type in hibernate hbm?

i am using hibernate. it has id column with 20 precisions as below but of NUMBER type.

NUMBER(38,20) - this is the size given to id column of the table(Oracle database).

This id is generated by our application. in entity if i use Float or Double it cannot accommodate 20 precisions. but java.math.BigDecimal can accommodate these many precisions. but the problem is can i use BigDecimal in hbm as below? will there be any problems? some times i may not send id with precisions. that time will hibernate generates any empty precision and inserts?

<id name="someId" column="SOME_ID" type="java.math.BigDecimal"/>

Please suggest!

like image 651
user1016403 Avatar asked Nov 24 '11 07:11

user1016403


People also ask

How to use HBM in hibernate?

This tutorial is helpful to understand about hbm.xml In hibernate, there is two way of mapping - first one is by using hibernate annotation and second one is by using hbm.xml. When you use hbm.xml, just modify default hibernate SessionFactory class in hibernate-cfg.xml by passing your "hbm.xml" file path as an argument to resource method.

What are identifiers in hibernate?

Identifiers in Hibernate represent the primary key of an entity. This implies the values are unique so that they can identify a specific entity, that they aren't null and that they won't be modified. Hibernate provides a few different ways to define identifiers. In this article, we'll review each method of mapping entity ids using the library.

Why are hibernate entity IDs unique?

This implies the values are unique so that they can identify a specific entity, that they aren't null and that they won't be modified. Hibernate provides a few different ways to define identifiers. In this article, we'll review each method of mapping entity ids using the library. 2. Simple Identifiers

How do I generate an ID in hibernate?

Hibernate will generate an id of the form “8dd5f315-9788-4d00-87bb-10eed9eff566”. 3.2. IDENTITY Generation This type of generation relies on the IdentityGenerator, which expects values generated by an identity column in the database. This means they are auto-incremented. To use this generation type, we only need to set the strategy parameter:


1 Answers

You can use type="big_decimal". Under no circumstances should you even attempt to use Float or Double for this.

like image 117
J. Stoever Avatar answered Oct 14 '22 04:10

J. Stoever