Thursday, 15 August 2013

Database column requires int, but doesn't throw exception when string is inputted

Database column requires int, but doesn't throw exception when string is
inputted

I have a rest service which has a database. When I add an entity to my
database in an EJB using a entityfacade, one entity variable price
requires an real. If I input the price as a string in xml format from a
client, no exception is thrown and the database registers 0 instead. If I
make the variable too large the proper exception is thrown.
Any ideas of why this is happening? Or is there a way if setting my
database table to accept integer only?
public class Books implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
//@NotNull
@Column(name = "BOOKID")
private Integer bookid;
@Basic(optional = false)
@NotNull
@Column(name = "ISBN")
private long isbn;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 40)
@Column(name = "PUBLISHER")
private String publisher;
@Column(name = "QUANTITY")
private int quantity;
@Basic(optional = false)
@NotNull
@Column(name = "PRICE")
private float price;
CREATE TABLE BOOKS (BOOKID INTEGER DEFAULT AUTOINCREMENT: start 1
increment 1 NOT NULL GENERATED ALWAYS AS IDENTITY, ISBN BIGINT
NOT NULL, TITLE VARCHAR(100) NOT NULL, COPYRIGHT VARCHAR(4) NOT NULL,
PUBLISHER VARCHAR(40) NOT NULL, QUANTITY INTEGER, PRICE REAL NOT NULL,
PRIMARY KEY (BOOKID));

No comments:

Post a Comment