I’m trying insert on a view using datanucleus, the problem is, when i put @Persistent in field that has no corresponding field in table and i catch the error:
11:03:42,782 INFO [br.com.sigel.server.censo.dao.persistentDAO.ParametrosCensoDAO] – javax.jdo.JDODataStoreException: Exception thrown flushing changes to datastore
NestedThrowables:
java.sql.BatchUpdateException: ORA-01733: virtual column not allowed here
but when i put @NotPersistent, don’t get fields from view and fields stay empty.
I need these fields are completed according to the view, but never overwritten (read-only).
My code is:
@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;
…
My view is:
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
);
Anyone can help me? Thank you.
As far as I know you can’t use JDO for write operations on a view (even though the DB might support it). You can however use a DataNucleus extension (so its not part of the JDO specification) for read purposes on a view. This Documentenion of DataNucleus show you how you can use the views for readonly purposes.
The ‘@NotPersisted’ annotation tells DataNucleus it should leave the field alone so its only logical it does not populate it with data from the DB.
I also noticed some other things in your code example; Why aren’t you using primitives for booleans and integers ? Their Object counter parts (which you are using) are generally only used for use in Generic collections and if you really need ‘null’ as a value. Autoboxing ensures that you don’t see the difference. Primatives are faster and don’t use as much memory and therefor it is common practice to use those instead.