我使用一个消息驱动bean来创建一个实体并将其添加到数据库中。
但是,当我创建实体并将其持久化到数据库中时,这些值将变为空。
创建实体的代码。
public void createSuggestion(Date date, String content) {
System.out.println("Suggestion Content is " + content);
System.out.println("Suggestion Date is " + date.toString());
SuggestionEntity suggestion = new SuggestionEntity();
suggestion.create(date, content);
em.persist(suggestion);
}
这是system.out.println结果。
建议内容是hello。这是个测试。
建议日期为2013年10月22日星期二20:28:39 SGT
但是,当输入数据库时,它们变为空。
我的建议实体的代码太长。
所以我把它包含在下面的Pastebin链接中。
http://pastebin.com/YMcknQTC
有什么帮助吗?:)
最佳答案
本部分:
public void create(Date date, String content) {
this.setSuggestionDate(suggestionDate);
this.setSuggestionContent(suggestionContent);
}
应该是这样的:
public void create(Date date, String content) {
this.setSuggestionDate(date);
this.setSuggestionContent(content);
}
关于java - 创建实体时数据库表中的空值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19518811/