-->
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.  [ 4 posts ] 
Author Message
 Post subject: why there's not-null property check when deleting objects ?
PostPosted: Sun Apr 09, 2006 10:04 pm 
Newbie

Joined: Fri Oct 28, 2005 10:32 pm
Posts: 13
I delete an object with a property(not the id)
which the attribute not-null is true.
I just create a transient object and set the id to the identifier.
then I called delete(obj).
it failed and throwed a PropertyValueException.

finally I need to set the not-null property to a not null value to settle
this problem.

but what is needed to delete a row
is only the identifier.why does it need this?

thank you in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 11, 2006 6:28 am 
Beginner
Beginner

Joined: Mon May 02, 2005 6:17 pm
Posts: 41
delete

public void delete(Object object)
throws HibernateException
Remove a persistent instance from the datastore. The argument may be an instance associated with the receiving Session or a transient instance with an identifier associated with existing persistent state. This operation cascades to associated instances if the association is mapped with cascade="delete".


You need to set the ID of that object. Or you can use query to delete

_________________
www.globalresearch.ca


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 12, 2006 3:44 am 
Newbie

Joined: Fri Oct 28, 2005 10:32 pm
Posts: 13
but I do set the id,which is enough to query the object;
the not null property is another property other than ID.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 18, 2006 4:04 pm 
Beginner
Beginner

Joined: Thu Sep 22, 2005 10:48 am
Posts: 30
Location: Rio de Janeiro, Brazil
I have the same problem

Hibernate-Version: 3.0.final

HBM
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="br.com.teste.model.Categoria" table="CATEGORIA" select-before-update="true">
        <id name="id" type="java.lang.Long">
            <column name="ID" precision="12" scale="0" />
            <generator class="sequence">
               <param name="sequence">SQ_CATEGORIA</param>
            </generator>
        </id>
        <property name="nome" type="java.lang.String">
            <column name="NOME" length="100" not-null="true" />
        </property>
        <set name="produtos" inverse="true">
            <key column="CATEGORIA_ID" />
            <one-to-many class="br.com.teste.model.Produto" />
        </set>
    </class>
</hibernate-mapping>



App
Code:
      Categoria categoria = new Categoria();
      categoria.setId(Long.valueOf("50"));
      
      Session s = HibernateSessionFactory.getSession();
      
      Transaction tx = s.beginTransaction();
      s.delete(categoria);
      tx.commit();
      
      s.close();


Exception
Code:
org.hibernate.PropertyValueException: not-null property references a null or transient value: br.com.teste.model.Categoria.nome
   at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.