-->
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.  [ 6 posts ] 
Author Message
 Post subject: removing value from Map collection doesn't update database
PostPosted: Tue Nov 30, 2004 12:05 pm 
Hibernate version: 2.1.7

Mapping documents:

<class name="Folder" lazy="true">
<id name="ID">
<generator class="native"/>
</id>
<version name="version"/>
...
<map name="attributes" cascade="all-delete-orphan" lazy="true" table="folder_attributes">
<key column="id"/>
<index column="key" type="string"/>
<element column="value" type="string"/>
</map>
</class>

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

session.beginTransaction();
...
Folder folder = session.get(...);
...
folder.getAttributes().remove("abc");
transaction.save(folder);
transaction.commit();



This snip is from a webapplication we're writing where for each http request a session is opened, a transaction is created, objects are read from the session, manipulated and saved to the session.

My problem is that:

1. When I try to remove key/values from the attribute map, nothing is changed to the database (the folder object is however written to the database as I can see from the debug logs).

2. When I try to update a key/value pair in the attribute map (by changing the value part for example), hibernate executes an insert statement (which fails the uniqueness constraints).

3. When I add a key/value to the attribute map, everything works fine!

Interestingly, when I keep the session open (i.e. ensure that only one user is hitting the webapp and keep the same session object open all the time) then changes to the attribute map are saved as expected.

Any thoughts?

G.


Top
  
 
 Post subject:
PostPosted: Tue Nov 30, 2004 12:19 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Sounds like a broken session-handling to me. Also a cascade setting for a map with <elements> does not make much sense.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 30, 2004 12:29 pm 
michael wrote:
Sounds like a broken session-handling to me. Also a cascade setting for a map with <elements> does not make much sense.


Dear Michael, thank you for the quick reply!

I set lazy to false and changed cascade to none, but that didn't help much.
You say you're suspecting a broken session. I'm using the default connection pooling (i.e. not any application server database pools). Do you have any advice on how to track down what is happening?

BR
G.


Top
  
 
 Post subject:
PostPosted: Tue Nov 30, 2004 12:46 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
I said broken session handling - if you can solve the problem by the way you handle your session, most likely the way you do it currently is messed up


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 01, 2004 6:38 am 
Helo again

I must apologise for the initial post, as I did a bad test. In fact, operations on the collection perform erratic and in a non predictable way even if used in a single-shot example, like:

Code:
Configuration config = new Configuration();
config.setProperties(System.getProperties());
SessionFactory sessionFactory = config.configure().buildSessionFactory();
Session session = sessionFactory.openSession();
session.connection().setAutoCommit(true);
Folder folder = (Folder)session.get(Folder.class, new Integer(1));
folder.getAttributes().remove("a1");
session.save(folder);
session.flush();
session.close();


which I run from the command line (so no application servers or anything).
The folder table initialy looks like:
Code:
ID | VALUE | KEY
1 | v1 | a1
1 | v2 | a2
1 | v3 | a3


and after the program has finished is exactly the same, the delete operation is not performed.

Any hints?
G.


Top
  
 
 Post subject:
PostPosted: Wed Dec 01, 2004 7:23 am 
Dear Michael

I think I found what was wrong. When a key exist, but the value is null then hibernate gets confused about which keys exist and which don't. Or, alternatively, I just don't know how to play with non-null constraints :)

Eitherway, thank you for your help!
BR
G.


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