[英]How do I make Apache Cayenne respect database defaults?
I have a postgres database with some defaults such as: 我有一个带有一些默认值的postgres数据库,例如:
CREATE TABLE product (
id serial,
name text,
created_at DEFAULT now(),
price numeric DEFAULT 9.99
);
How do I make Cayenne honour those defaults when I do a context.newObject(Product.class)
? 执行context.newObject(Product.class)
时,如何使Cayenne遵守这些默认设置?
Currently I am hooking into the onPostAdd
callback and then setting my defaults there, though I was wondering if that's the only way to do it? 目前,我想了解onPostAdd
回调,然后在其中设置默认值,尽管我想知道这是否是唯一的方法吗? Can't I use my database defaults somehow to keep it DRY
? 我不能以某种方式使用数据库默认值来保持DRY
吗?
I am using Apache Cayenne 4.1. 我正在使用Apache Cayenne 4.1。
Unfortunately onPostAdd
is your best bet. 不幸的是onPostAdd
是您最好的选择。 This is object-relational impedance at its worst. 这是最坏的对象关系阻抗。 As one of Cayenne authors I am well aware of this issue. 作为Cayenne的作者之一,我非常了解这个问题。 Wish there was a DRY solution. 希望有一个DRY解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.