Datanucleus/Roo/GWT - 保留带有日期字段的 beans 时出现问题
我尝试运行示例 GWT/Google Appengine 应用程序 - ROO 使用 roo 命令“scriptexpense.roo”生成的费用(按照建议 此处)...
此应用程序使用 datanucleus-core - 1.1.6以及 HSQLDB 作为内存数据库。
我能够运行该应用程序并成功存储和检索 Employee 对象。 (这些 Employee 对象没有任何日期类型字段,只有 string 和 int 字段)。
但我在存储“报告”对象时遇到问题,应用程序打印错误消息“意外的服务器错误”。查看日志和调试,发生了这个意外错误,因为试图将 null 存储在非空日期类型字段(“创建”日期字段)中,
这就是事情变得复杂的地方......查看此 Report 类的源代码, “创建”日期字段未指定为“非空”字段(缺少 @notnull 注释)。为了确认这一点,我将数据库更改为 Postgresql 并检查了自动生成的架构,发现该日期字段确实被标记为“非空”。
这意味着 DataNucleus 在自动模式生成期间始终将日期字段标记为“非空”。
我通过将 ORM 库更改为 Hibernate 进一步证实了这一点,相同的代码没有任何问题,并且能够在 HSQL 和 Postgres DB 中保存带有日期字段的报表对象。
这是 DataNucleus 的错误吗?还有其他人看到这个问题吗?
I tried running the sample GWT/Google Appengine application - expenses generated by ROO using the roo command "script expenses.roo" (as advised here)...
This app uses datanucleus-core - 1.1.6 and a HSQLDB as the in-memory database.
I was able to run the application and successfully store and retrieve Employee objects. (These Employee objects do not have any date type fields but have only string and int fields).
But I am having problems storing the 'Report' objects with the App printing an error message 'Unexpected Server Error'. Looking at the logs and debugging, this unexpected error happened because of trying to store null in a not null date type field ('created' date field)
This is where it gets complicated... Looking at the source code for this Report class, the 'created' date field is not specified as a 'not null' field (missing the @notnull annotation). To confirm this I changed the databse to Postgresql and inspected the auto-generated schema and found that this date field is indeed marked as 'not null'.
This means that DataNucleus during auto-schema generation always marks date fields as 'not null'.
I further confirmed this by changing the ORM library to Hibernate and the same code worked with out any problems and was able to save report objects with date fields in both HSQL and Postgres DB.
Is it a bug with the DataNucleus and is anyone else seeing this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用 DataNucleus 作为带有许多日期字段(如时间戳或 DATE)的 JPA,并且完全没有问题。 SchemaTool 始终在 DDL 中将它们创建为“NULL”(允许空值)。由于您没有引用实体类或日志,因此没有更多可用的帮助
I've used DataNucleus as JPA with many date fields (as timestamp, or DATE) and had no problem at all. SchemaTool always creates them as "NULL" in the DDL (allowing nulls). Since you don't quote the Entity class or the logs no help more available