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