Reputation: 45
I am using hibernate to create entity. The attributes I used are as below :
@Id
@SequenceGenerator(name = "customer-id-gen", sequenceName = "CUSTOMERS_SEQ", allocationSize = 1)
@GeneratedValue(generator = "customer-id-gen", strategy = GenerationType.SEQUENCE)
@Column(name = "CUSTOMER_ID", length = 4, nullable = false)
private int customerId;
@Column(name = "CUSTOMER_NAME", length = 40, unique = false, nullable = false)
private String customerName;
@Column(name = "PHONE_NO", unique = true, nullable = true, length = 10)
private Long phoneNo;
However as i can see through logs that table created is as following structure :
create table CUSTOMER_ALL (
CUSTOMER_ID number(10,0) not null,
CUSTOMER_NAME varchar2(40 char) not null,
PHONE_NO number(19,0) unique,
primary key (CUSTOMER_ID)
)
I am not able to figure out how the phone_no
attribute is converted into 19 size and customer_id
to 10 ?
Upvotes: 0
Views: 44
Reputation: 5829
As per JPA, length only applies to String types. Type 'int' controlled the storage size of CUSTOMER_ID. Type 'Long' controlled the storage size of PHONE_NO.
Do you really want a phone number to be a Long? Better a String?
Upvotes: 1