-->
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.  [ 10 posts ] 
Author Message
 Post subject: Will not delete certain object...
PostPosted: Wed Dec 03, 2003 1:42 am 
Regular
Regular

Joined: Sat Oct 18, 2003 11:53 am
Posts: 55
I have a particular object (Group) that the app will not delete for some reason. It deletes other groups just fine, but this one instance it just ignores. Here is some of the relative debug output..

Code:
....
2003-12-02 23:38:59,703 DEBUG [main] impl.SessionImpl (SessionImpl.java:2696) - Processing unreferenced collections
2003-12-02 23:38:59,703 DEBUG [main] impl.SessionImpl (SessionImpl.java:2707) - Scheduling collection removes/(re)creates/updates
2003-12-02 23:38:59,703 DEBUG [main] impl.SessionImpl (SessionImpl.java:2276) - Flushed: 0 insertions, 0 updates, 0 deletions to 43 objects
2003-12-02 23:38:59,703 DEBUG [main] impl.SessionImpl (SessionImpl.java:2281) - Flushed: 0 (re)creations, 0 updates, 0 removals to 31 collections
2003-12-02 23:38:59,703 DEBUG [main] impl.Printer (Printer.java:74) - listing entities:
...
...
2003-12-02 23:38:59,733 DEBUG [main] impl.Printer (Printer.java:81) - com.ldi.db.hibernate.ModuleReport{report=Report#18, moduleReportId=1351, reportFields=uninitialized, groupModule=GroupModule#314}
2003-12-02 23:38:59,743 DEBUG [main] impl.Printer (Printer.java:78) - more......
2003-12-02 23:38:59,743 DEBUG [main] impl.SessionImpl (SessionImpl.java:2313) - executing flush
2003-12-02 23:38:59,743 DEBUG [main] impl.SessionImpl (SessionImpl.java:2727) - post flush
2003-12-02 23:38:59,743 DEBUG [main] impl.SessionImpl (SessionImpl.java:501) - closing session
2003-12-02 23:38:59,743 DEBUG [main] impl.SessionImpl (SessionImpl.java:3321) - disconnecting session


Is there a common reason for this? I am stumped. Thanks.

Matt Dowell


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 2:20 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
do you return VETO from Lifecycle.onDelete() ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 11:06 am 
Regular
Regular

Joined: Sat Oct 18, 2003 11:53 am
Posts: 55
gavin wrote:
do you return VETO from Lifecycle.onDelete() ?


Nope. I had ten "Groups" in my test case, and nine of them will delete, but this one will not. The only difference is the data.. Are there any situations where Hibernate will not complete a deletion but not display an error?

Matt


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 11:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Enable the Hibernate log and see what it says.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 12:02 pm 
Regular
Regular

Joined: Sat Oct 18, 2003 11:53 am
Posts: 55
gavin wrote:
Enable the Hibernate log and see what it says.


Yeah, I did. I posted what I think are the relative parts above, granted I dont know what to look for. The output seems normal except there are no exceptions thrown and there is no SQL generated.

If there are FK problems, will it throw an exception? Won't it try to execute the delete anyways?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 12:03 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Yes, it will try to delete anyway. Are you sure you flush the session? Are you deleting a detached object - if so, is your unsaved-value mapping correct?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 12:15 pm 
Regular
Regular

Joined: Sat Oct 18, 2003 11:53 am
Posts: 55
gavin wrote:
Yes, it will try to delete anyway. Are you sure you flush the session? Are you deleting a detached object - if so, is your unsaved-value mapping correct?


Yeah all good, that's the wierd part. The app will delete these objects 9 times out of 10. Everything is exactly the same except for the data. I think the only thing different with the data, in this instance, is that the undeletable object has a larger tree.


Top
 Profile  
 
 Post subject: Similar and Similarly Odd delete behavior
PostPosted: Thu Dec 18, 2003 12:50 am 
Newbie

Joined: Thu Dec 18, 2003 12:30 am
Posts: 9
I'm using v2.0.3 and attempting to write some unit tests for my Hibernate DAO implementation.

Part of the unit tests is cleaning up created objects in the database, but the objects don't get deleted unless I delete the object twice.

My test looks like this:

Code:
// ...
HibernateUser createdUser =
    (HibernateUser)userMgr.createUser(FOO_EMAIL, FOO_PASSWORD);
usersToDelete.add(createdUser);
session.flush();
// ...
HibernateUser retrievedUser =
    (HibernateUser)userMgr.getUser(FOO_EMAIL, FOO_PASSWORD);
// ...


the create user method looks like:
Code:
public User createUser(String email, String password)
    throws UserException
{
    HibernateUser user = new HibernateUser(email, password);
    Session session = getSession();
    Serializable id = null;
    try
    {
        id = session.save(user);
        session.flush();
    }
    catch (HibernateException err)
    {
        throw new UserException(email, err);
    }
    user.setId(id);
    return user;
}


The getUser method looks like:
Code:
public User getUser(String email, String password)
    throws UserException
{
    Session session = getSession();
    Query query = null;
    List results = null;
    try
    {
        query = session.getNamedQuery(
          (QRY_USER_BY_EMAIL_PASSWORD);
        query.setParameter(PARAM_EMAIL, email);
        query.setParameter(PARAM_PASSWORD, password);
        results = query.list();
    }
    catch (Exception err)
    {
        throw new UserException(email, err);
    }
    if (!results.isEmpty())
    {
        user = (User)results.get(0);
    }
    return user;
}


My clean up code is:
Code:
private void deleteUsers() throws Exception
{
    Iterator users = usersToDelete.iterator();
    Object obj = null;
    while (users.hasNext())
    {
        obj = users.next();
        session.delete(obj);
    }
    session.delete("from HibernateUser");
}


If I don't put that last delete, the created user doesn't get deleted. Even more odd, that last delete causes the created user to get deleted but not other records in the table that I inserted manually.

Is this the same problem, and is there a better solution than dual deletes?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 18, 2003 3:42 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Have a look at the Hibernate log.


Top
 Profile  
 
 Post subject: Got it figured out...
PostPosted: Thu Dec 18, 2003 1:11 pm 
Newbie

Joined: Thu Dec 18, 2003 12:30 am
Posts: 9
I figured it out. I wasn't flushing the session explicitly. When I replaced the second delete with a session.flush() call everything worked. Still seems like odd behavior, but I can live with this solution a lot easier than the other.

Thanks


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