【问题标题】:Annotations in datanucleus数据核中的注释
【发布时间】:2013-11-27 21:31:06
【问题描述】:

我正在尝试使用 datanucleus 在视图上插入,问题是,当我将 @Persistent 放入表中没有相应字段的字段时,我发现了错误:

11:03:42,782 INFO [br.com.sigel.server.censo.dao.persistentDAO.ParametrosCensoDAO] - javax.jdo.JDODataStoreException:抛出异常,刷新对数据存储的更改 嵌套的Throwables: java.sql.BatchUpdateException: ORA-01733: virtual column not allowed here

但是当我输入@NotPersistent 时,不要从视图中获取字段并且字段保持为空。 我需要这些字段根据视图完成,但永远不会被覆盖(只读)。

我的代码是:

    @PersistenceCapable(identityType = IdentityType.APPLICATION,detachable="true", table="VW_FILA_CENSO") 
    @Sequence(datastoreSequence = "SEQ_SG_FICE_SEQ", strategy = SequenceStrategy.CONTIGUOUS, name = "seqFice")
    @Cacheable("false")
    public class SG_Fila_Censo implements BeanModelTag,Serializable {
private static final long serialVersionUID = 1L;
@NotPersistent 
private Integer escoSeq;
@Persistent(primaryKey="true", valueStrategy=IdGeneratorStrategy.SEQUENCE, sequence="seqFice")
    private Integer fice_seq;

@Persistent
private Date fice_data_solicitacao; 

@Persistent
private Boolean fice_processando;

@Persistent
private Boolean fice_priorizado;

@Persistent
private Integer fice_rece_seq;

@Persistent
private Integer fice_colb_seq;

@Persistent
private String unidade_escolar;

@Persistent
private String nome_colaborador;

@Persistent
private Integer etapa_relatorio;

@Persistent
private String cree_cod;

...

我的看法是:

CREATE OR REPLACE VIEW "SCH_SECULT3"."VW_FILA_CENSO"
(FICE_SEQ,FICE_DATA_SOLICITACAO,FICE_PROCESSANDO,FICE_PRIORIZADO,FICE_RECE_SEQ,FICE_COLB_SEQ,unidade_escolar,nome_colaborador,cree_cod,etapa_relatorio)
AS
(SELECT
    SG_FILA_CENSO.FICE_SEQ,
    SG_FILA_CENSO.FICE_DATA_SOLICITACAO,
    SG_FILA_CENSO.FICE_PROCESSANDO,
    SG_FILA_CENSO.FICE_PRIORIZADO,
    SG_FILA_CENSO.FICE_RECE_SEQ,
    SG_FILA_CENSO.FICE_COLB_SEQ,
    VW_RELATORIO_CENSO.unidade_escolar,
    VW_RELATORIO_CENSO.nome_colaborador,
    VW_RELATORIO_CENSO.cree_cod,
    VW_RELATORIO_CENSO.rece_etapa
    FROM SG_FILA_CENSO,VW_RELATORIO_CENSO
    where SG_FILA_CENSO.fice_rece_seq = VW_RELATORIO_CENSO.rece_seq
);

有人可以帮助我吗?谢谢。

【问题讨论】:

    标签: annotations datanucleus persistent


    【解决方案1】:

    您可以放置​​@Column(insertable = false) 注释(例如@Column(name = "SOURCE_DESC", length = 512, insertable = false) - 计算的数据库视图属性)。这告诉持久性单元不要将此列值插入数据库表。但是,在从 DB 视图中检索数据时仍会查询值。

    格迪米纳斯

    【讨论】:

      【解决方案2】:

      据我所知,您不能使用 JDO 对视图进行写操作(即使数据库可能支持它)。但是,您可以使用 DataNucleus 扩展(因此它不是 JDO 规范的一部分)来读取视图。 DataNucleus 的 Documentenion 向您展示了如何将视图用于只读目的。

      “@NotPersisted”注释告诉 DataNucleus,它应该不理会该字段,因此它唯一合乎逻辑的是它不会使用来自 DB 的数据填充它。

      我还注意到您的代码示例中的其他一些内容;为什么不使用布尔值和整数的原语?它们的对象计数器部分(您正在使用)通常仅用于通用集合中,并且如果您确实需要“null”作为值。自动装箱可确保您看不到差异。 Primatives 速度更快,并且不使用太多内存,因此通常使用它们来代替。

      【讨论】:

        猜你喜欢
        • 2018-02-23
        • 2016-01-01
        • 2018-12-16
        • 1970-01-01
        • 1970-01-01
        • 2016-06-05
        • 2013-01-27
        • 2014-12-21
        • 1970-01-01
        相关资源
        最近更新 更多