简体   繁体   中英

Database schema not as per hibernate annotations

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 ?

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM