-->
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.  [ 2 posts ] 
Author Message
 Post subject: Dirty map not updating without a specified merge call
PostPosted: Fri Aug 10, 2007 7:35 pm 
Beginner
Beginner

Joined: Wed Nov 30, 2005 10:25 pm
Posts: 25
I'm having an issue with entities in a map being persisted. Here is the code:

Code:
@Entity
@Name("user")
@Table(name = "customer_user")
@Scope(ScopeType.SESSION)
@SequenceGenerator(name = "seq", sequenceName = "customer_user_seq")
public class User {
...

  @OneToMany(cascade = javax.persistence.CascadeType.PERSIST)
  @JoinColumn(name = "user_id", updatable = false)
  @MapKey(name = "name")
  @Cascade( { CascadeType.ALL, CascadeType.DELETE_ORPHAN })
  @Valid
  private Map<String, UserPreference> preferences =
      new HashMap<String, UserPreference>();

  public void setPreference(String name, String value)
  {
    UserPreference pref = this.preferences.get(name);
    if (pref == null)
    {
      pref = new UserPreference();
      pref.setName(name);
      pref.setValue(value);
      this.preferences.put(name, pref);
    }
    else
    {
      pref.setValue(value);
    }
  }


Code:
@Name("userPreference")
@Entity
@Table(name = "user_preference")
@Scope(ScopeType.CONVERSATION)
@SequenceGenerator(name = "seq", sequenceName = "user_preference_seq")
public class UserPreference { ... (no reverse mapping)


Now if I call:
user.setPreference("test", "testval");

The preference will not be inserted unless I call:
entityManager.merge(user);

Since the map is marked as dirty, and the user object is not detached, shouldn't be picked up automatically and the cascade automatically work? What do I need to do to ensure that the cascade is picked up. I don't have a reference to the entity manager in the user object, so cannot call persist in the setPreference method

FYI, both objects have a parent class with a version property and an ID:
Code:
  @Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seq")
  private Long id;

  @Basic
  @Version
  @Column(name="modified_dt")
  private Timestamp modified;


I can call the merge, I'd just like to know why I have to.

Hibernate version: 3.2.4 sp1
Hibernate annotations version: 3.3.0.GA
Hibernate entityManager version: 3.3.1.GA


Top
 Profile  
 
 Post subject: Found the issue
PostPosted: Mon Aug 13, 2007 12:08 pm 
Beginner
Beginner

Joined: Wed Nov 30, 2005 10:25 pm
Posts: 25
It was a configuration problem with my usage of JBossSeam (was not using @Transactional and TransactionalPhaseListener) with my POJO methods.

-Andrew


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