-->
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: Incorrect mappings: collection was not processed by flush()
PostPosted: Wed Nov 17, 2010 2:10 am 
Newbie

Joined: Tue Nov 16, 2010 8:34 am
Posts: 3
Hi all

Please help me with my incorrect understanding of mappings, cascade and flush.
I have various data model classes that are linked: Event --> EventDateTime --> TicketCategory -->ManyToMany<-- Block.
The Block data model is also linked via another path: Event --> Venue --> Layout --> Block --> Seat.
Currently my test data does not include any Layout, Block and Seat data. There is only Event, EventDateTime, TicketCategory and Venue data.

Whenever a TicketCategory have loaded (via a EventDateTime instance being loaded), when a flush it performed by Hibernate, I get the flush exception below (collection [...model.ticket.TicketCategory.blocks] was not processed by flush()).
I assumed that since the link between the TicketCategory and Blocks is a lazy loaded, cascade none (default), Hibernate not not care about this link when saving the TicketCategory. If I call ticketCategory.getBlocks() prior to saving the data, obviously Hibernate then initializes the (non-existing) lazy loaded collection of blocks and the error does not occur.

Q1: Why when working with an EventDateTime instance are the corresponding TicketCategory instances loaded by Hibernate? Cascade is default (none) and lazy loaded.

Q2: Why does TicketCategory care about Blocks when it is flushed if the cascade is none? Is it the validation annotations or is this how Hibernate works?

Code:
public class EventDateTime extends BaseModelData {

  private List<TicketCategory> ticketCategories;

  @NotEmpty
  @OneToMany(mappedBy="dateTime")
  public List<TicketCategory> getTicketCategories() {
    return ticketCategories;
  }

  public void setTicketCategories(List<TicketCategory> ticketCategories) {
    this.ticketCategories = ticketCategories;
  }
}

public class TicketCategory extends BaseModelData {

  private Set<Block> blocks;

  @ManyToMany
  @JoinTable(name="ticket_category_venue_blocks",
             joinColumns= { @JoinColumn(name="ticket_category_id") },
             inverseJoinColumns= { @JoinColumn(name="venue_block_id") } )   
  public Set<Block> getBlocks() {
    return blocks;
  }

  public void setBlocks(Set<Block> blocks) {
    this.blocks = blocks;
  }
}

public class Block extends BaseModelData {
  //Tried various mappings, nothing seems to make a difference
//Currently no mapping to TicketCategory
}


Exception is:
Code:
ERROR org.hibernate.AssertionFailure - an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: collection [...model.ticket.TicketCategory.blocks] was not processed by flush()
   at org.hibernate.engine.CollectionEntry.postFlush(CollectionEntry.java:228)
   at org.hibernate.event.def.AbstractFlushingEventListener.postFlush(AbstractFlushingEventListener.java:356)
   at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:65)
   at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1175)
   at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1273)
   at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:117)
   at ...dao.event.EventDaoHibernateImpl.updateAvailableNumberOfTickets(EventDaoHibernateImpl.java:119)
        ...


Hibernate 3.5.5-Final
Hibernate Annotations 3.4.0.GA
Hibernate Validator 4.1.0.Final
Spring 3.0.4.RELEASE

If anyone can please correct my incorrect mappings and understanding, that would be great.

Thanks
Aisling


Top
 Profile  
 
 Post subject: Re: Incorrect mappings: collection was not processed by flush()
PostPosted: Wed Nov 17, 2010 3:34 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
The error message indicates that something is happening during the flush that causes non-initialized lazy objects to be initialized. It is fairly easy to find out what is triggering the loading. Put something like this in your EventDateTime.getTicketCategories() and TicketCategory.getBlocks() methods:

Code:
new Exception().printStackTrace();


Then you will get a nice output of stacktraces and you will see exactly what other code is calling the getter methods. Typical sources of the problem can be an Interceptor, an event listener or maybe the @NotEmpty annotation on the getTicketCategories().


Top
 Profile  
 
 Post subject: Re: Incorrect mappings: collection was not processed by flush()
PostPosted: Thu Nov 18, 2010 3:06 am 
Newbie

Joined: Tue Nov 16, 2010 8:34 am
Posts: 3
Thanks for the suggestion (should of thought of that myself - doh) and you were right, its the @NotEmpty annotation that causes the EventDateTime data to load the TicketCategory instances. I do want to use the validation annotations but not if it causes lazy loading collections to be loaded. Need to do some more reading on this. Thanks again.


Top
 Profile  
 
 Post subject: Re: Incorrect mappings: collection was not processed by flush()
PostPosted: Thu Nov 18, 2010 3:15 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Maybe you can implement your own validation rule. I have not any experience with that but it should be possible to check if the collection is an instance of org.hibernate.collection.PersistentCollection and then use some methods in that interface to avoid initializing the collection. See http://docs.jboss.org/hibernate/core/3. ... ction.html


Top
 Profile  
 
 Post subject: Re: Incorrect mappings: collection was not processed by flush()
PostPosted: Thu Nov 18, 2010 3:54 am 
Newbie

Joined: Tue Nov 16, 2010 8:34 am
Posts: 3
Thanks for the link (looking...).

For the moment, I am using a group to determine when the collection should be checked for data.

Code:

public class EventDateTime extends BaseModelData {
@NotEmpty(groups={PrePersistUpdateData.class})
  @OneToMany(mappedBy="dateTime")
  public List<TicketCategory> getTicketCategories() {
    return ticketCategories;
  }
}

public interface PrePersistUpdateData extends PrePersistNewData {
}

public interface PrePersistNewData extends Default {
}


(I knew about groups, my brain was obviously not in gear this week.)
Thanks.


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.