How to enforce DB field size limit to related Java String?
Posted
by Sri Sankaran
on Stack Overflow
See other posts from Stack Overflow
or by Sri Sankaran
Published on 2010-04-30T12:15:14Z
Indexed on
2010/04/30
12:37 UTC
Read the original article
Hit count: 170
What is the correct way to defend against trying to store more text than can be accommodated in a VARCHAR2 database field?
Say the PARTNER_ROLE field of the REGISTRATIONS table is declared as VARCHAR2(80).
This field is mapped in the Registration class in Java as
public class Registration {
@Column(name=”PARTNER_ROLE” length=”80”)
private String partnerRole;
}
However, the setPartnerRole() method allows the user to stuff a string of any length. The problem is encountered only when one subsequently tries to insert or update the REGISTRATIONS record. Oracle complains.
What is the correct way to handle this situation?
© Stack Overflow or respective owner