从数据库返回值时的数字格式异常(JPA) [英] Number format exception when returning values from database(JPA)
问题描述
我想用数据库中的一些值填充一个简单的h:datatable标记。但我得到一个例外,我无法找到原因:
I want to fill a simple h:datatable tag with some values from a database. But i get an exception and i cant find what is the reason:
java.lang.NumberFormatException:对于输入字符串:url
java.lang.NumberFormatException: For input string: "url"
这是我创建数据表的方式:
This is how i create the datatable:
<h:form>
<h:dataTable value="#{managementBB.retrieveRecords()}" var="record">
<h:column>
<f:facet name="header">URL</f:facet>
#{record.url}
</h:column>
<h:column>
<f:facet name="header">Submition date</f:facet>
#{record.submitionDate}
</h:column>
<h:column>
<f:facet name="header">Unacceptable</f:facet>
#{record.unnaceptableContent}
</h:column>
<h:column>
<f:facet name="header">Option</f:facet>
Something
</h:column>
</h:dataTable>
</h:form>
这是此页面背后的支持bean:
This is the backing bean behind this page:
@Named("managementBB")
@SessionScoped
public class ManagementBB implements Serializable{
@EJB
private ILinkManagerEJB linkManagerEJB;
public List<Record> retrieveRecords() {
return linkManagerEJB.retrieveRecords();
}
}
这是访问数据库以获取data:
This is the EJB that accesses the database to get the data:
@Stateless(name = "ejbs/LinkManagerEJB")
public class LinkManagerEJB implements ILinkManagerEJB {
@PersistenceContext
private EntityManager entityManager;
public List<Record> retrieveRecords() {
Query allRecords = entityManager.createNamedQuery("allrecordinfo");
return (List<Record>) allRecords.getResultList();
}
}
最后这是代表一行的JPA实体在数据库中:
And finally this is the JPA entity that represents a row in the database:
@Entity
@NamedQueries({@NamedQuery(name = "allrecordinfo",
query = "SELECT r.url, r.submitionDate, r.unnaceptableContent FROM Record r")})
public class Record {
@Id
@GeneratedValue
private long id;
@Column(nullable = false)
private String url;
@Column(nullable = false)
private String submitionDate;
@Column(nullable = false)
private boolean unnaceptableContent;
//Get set methods ...
}
你看,它看起来很简单,我以前做过这个,但现在我很困惑,我不知道为什么不工作。你能帮我找到我的错误吗?
As you see it looks simple, and I've done this before but now I am confused, I don't know why is not working. Could you help me find my error?
注意:我非常有信心查询语法没问题(我在eclipse的剪贴簿中测试过)
Note: I am pretty confident that the query syntax is ok (I tested it in eclipse's scrapbook)
推荐答案
查询不正确。
@NamedQueries({ @NamedQuery(name = "allrecordinfo", query = "SELECT r FROM Record r") })
@Entity
public class Record {
}
这篇关于从数据库返回值时的数字格式异常(JPA)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!