These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: update error
PostPosted: Tue Jun 13, 2006 8:13 am 
Newbie

Joined: Mon Jun 12, 2006 8:44 am
Posts: 13
I was trying to select some data from my Pedido class:
ICriteria criteria = NHibernateSessionManager.Instance.GetSession().CreateCriteria(typeof(Pedido));

criteria.Add(Expression.Not(Expression.Eq("CodAp", 0)))
.AddOrder(Order.Asc("CodAp"));

IPedidoDao pedidoDao = (new NHibernateDaoFactory()).GetPedidoDao();
List<Pedido> pedidos = pedidoDao.GetByCriteria(criteria);

and I received this error:

{"could not update: [ADFinance.Faturamento.Pedido#3173]"}
{"ORA-02291: restrição de integridade (ADSYSTEM.FK_PO_PEDIDO_MD_PRODUTO) violada - chave mãe não localizada\n"}

but I'm not trying to update anything...
As you can see in the mapping files I have a many-to-one relationship between Pedido and Produto, but the column in the Pedido class cod_produto can be null. Is that the problem?

Hibernate version: 1.0.2

Mapping documents:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="ADFinance.Faturamento.Pedido, ADFinance" table="T_ADF_PO_Pedido">
<id name="ID" column="cod_po" unsaved-value="0">
<generator class="native">
<param name="sequence">S_T_ADF_PO_Pedido</param>
</generator>
</id>

<property name="StatusFaturamento" column="cod_status_faturamento" />
<property name="TipoPedido" column="cod_tipo_pedido" />
<property name="CodPoOrigem" column="cod_po_origem" />
<property name="CodAp" column="cod_ap" />
<property name="CodCliente" column="cod_cliente" />
<property name="ValorComissao" column="valor_comissao" />
<property name="PorcentagemComissao" column="porcentagem_comissao" />
<property name="CodProduto" column="cod_produto" />
<property name="PeriodoVeiculacao" column="periodo_veiculacao" />

<many-to-one name="Praca" column="cod_praca" class="ADFinance.Comum.Praca, ADFinance" />
<many-to-one name="Meio" column="cod_meio" class="ADFinance.Comum.Meio, ADFinance" />
<many-to-one name="Campanha" column="cod_campanha" class="ADFinance.Comum.Campanha, ADFinance" />
<many-to-one name="Representante" column="cod_representante" class="ADFinance.Comum.Representante, ADFinance" />
<many-to-one name="Veiculo" column="cod_veiculo" class="ADFinance.Comum.Veiculo, ADFinance" />
<!--
<bag name="Itens" lazy="true" table="T_ADF_CP_PO_Item" inverse="false"
access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" >
<key column="cod_po" />
<one-to-many class="ADFinance.Faturamento.ItemPedido, ADFinance" />
</bag>-->
</class>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="ADFinance.Comum.Produto, ADFinance" table="T_ADF_MD_PROD">
<id name="ID" column="cod_produto" unsaved-value="0">
<generator class="native">
<param name="sequence">S_T_ADF_MD_PROD</param>
</generator>
</id>

<property name="CodProdutoCliente" column="cod_prod_cliente" />
<property name="NomeProduto" column="nome_produto" />

<many-to-one name="Cliente" class="ADFinance.Comum.Cliente, ADFinance" column="cod_cliente" />
</class>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

at NHibernate.Persister.EntityPersister.Update(Object id, Object[] fields, Object[] oldFields, Boolean[] includeProperty, Object oldVersion, Object obj, SqlString sqlUpdateString, ISessionImplementor session)
at NHibernate.Persister.EntityPersister.Update(Object id, Object[] fields, Int32[] dirtyFields, Object[] oldFields, Object oldVersion, Object obj, ISessionImplementor session)
at NHibernate.Impl.ScheduledUpdate.Execute()
at NHibernate.Impl.SessionImpl.Execute(IExecutable executable)
at NHibernate.Impl.SessionImpl.ExecuteAll(IList list)
at NHibernate.Impl.SessionImpl.Execute()
at NHibernate.Impl.SessionImpl.AutoFlushIfRequired(ISet querySpaces)
at NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria)
at NHibernate.Impl.CriteriaImpl.List()
at ADFinance.Data.GenericNHibernateDao`2.GetByCriteria(ICriteria criteria) in C:\Documents and Settings\Thiago\Meus documentos\GOLIVE\AD\Financeiro\ADFinance\ADFinance.Data\GenericNHibernateDao.cs:line 68
at FIFAT00101.ComboAps() in c:\Documents and Settings\Thiago\Meus documentos\GOLIVE\AD\Financeiro\ADFinance\Finance\FIFAT00101.aspx.cs:line 105
at FIFAT00101.Page_Load(Object sender, EventArgs e) in c:\Documents and Settings\Thiago\Meus documentos\GOLIVE\AD\Financeiro\ADFinance\Finance\FIFAT00101.aspx.cs:line 33
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Name and version of the database you are using: Oracle 8i

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:
{"could not update: [ADFinance.Faturamento.Pedido#3173]"}
{"ORA-02291: restrição de integridade (ADSYSTEM.FK_PO_PEDIDO_MD_PRODUTO) violada - chave mãe não localizada\n"}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 21, 2006 10:36 am 
Newbie

Joined: Mon Jun 12, 2006 8:44 am
Posts: 13
can anyone help with this??


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 22, 2006 3:33 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
Whith default Session.FlushMode, NHibernate saves all known changes before executing query - to avoid getting stale data as result.

Now, as the Prudoto is mapped as

<property name="CodProduto" column="cod_produto" />

NHibernate has no hint for executing saves/updates in correct order.

Maybe You should write it as

<many-to-one name="CodProduto" class="ADFinance.Comum.Produto, ADFinance" column="cod_produto"/>

Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 22, 2006 7:30 am 
Newbie

Joined: Mon Jun 12, 2006 8:44 am
Posts: 13
What about the enum cases? Because I can't map an enum as a many-to-one, I have to map it as a property.

And I haven't made any changes at all, I just binded de results from the getbycriteria method to a gridview.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 22, 2006 9:20 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
vintem wrote:
What about the enum cases? Because I can't map an enum as a many-to-one, I have to map it as a property.


If it is a enum, you:
a) do not have foreign key in database, so no problems during save.
b) Related database table contains all possible values (Probably including the 0 for unspecified enum value), so again no problems.

But as You map did specify class for produto, I did not think about this possibility.

vintem wrote:
And I haven't made any changes at all, I just binded de results from the getbycriteria method to a gridview.


I ahve no experience with gridview and NHIbernate, but maybe the gridview is creating a new instance of object? (To be shown as empty or new item)

Gertt

_________________
If a reply helps You, rate it!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.