数据库列需要int,但在输入字符串时不会抛出异常

时间:2013-08-15 23:26:43

标签: java xml database

我有一个有数据库的休息服务。当我使用entityfacade在EJB中向我的数据库添加实体时,一个实体变量价格需要一个实数。如果我从客户端以xml格式输入价格作为字符串,则不会抛出任何异常,数据库也会注册0。如果我使变量太大,则抛出适当的异常。

有关为何发生这种情况的任何想法?或者有没有办法将我的数据库表设置为仅接受整数?

@Entity
@Table(name = "BOOKS", catalog = "", schema = "DAVID")
@XmlRootElement

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));

0 个答案:

没有答案