hi
I have a strange problem I haven't been able to figure out. This doesn't happen from my web app, but happens when I write a mock test which should behave the exact same way. I'm stumped
I have a very simple unidirectional one-to-many relationship w/ join table,
Code:
// this is the parent class, has a list of items
@Entity
@Table(name="tbl_purchase_request")
public class PurchaseRequest implements Serializable {
@OneToMany(cascade=CascadeType.ALL)
@JoinTable(name="tbl_join_purchase_request_to_item",
joinColumns=@JoinColumn(name="purchaseRequest"),
inverseJoinColumns=@JoinColumn(name="item"))
private List<Item> items = new ArrayList<Item>();
}
// child class
Entity
@Table(name="tbl_item")
public class Item implements Serializable {
// a bunch of strings and stuff
}
i get a standard join table like this
Code:
tbl_join_purchaseRequest_to_item:
purchaseRequest item
1 1
1 2
1 3
2 4
2 5
3 6
from my web context everything is fine, but from the unit tests, the parent and child tables are both filled out, but the join table is empty!!
here's the logs, you can see it does the cascade but nowhere does it do anything about a join table
Code:
11:17:43,036 DEBUG Cascade:237 - processing cascade ACTION_SAVE_UPDATE for: edu.upmc.ccweb.purchasing.model.PurchaseRequest
11:17:43,036 DEBUG Cascade:285 - cascade ACTION_SAVE_UPDATE for collection: edu.upmc.ccweb.purchasing.model.PurchaseRequest.items
11:17:43,036 DEBUG CascadingAction:133 - cascading to saveOrUpdate: edu.upmc.ccweb.purchasing.model.Item
11:17:43,036 DEBUG AbstractSaveEventListener:489 - transient instance of: edu.upmc.ccweb.purchasing.model.Item
11:17:43,036 DEBUG DefaultSaveOrUpdateEventListener:161 - saving transient instance
11:17:43,036 DEBUG AbstractSaveEventListener:152 - saving [edu.upmc.ccweb.purchasing.model.Item#<null>]
11:17:43,051 DEBUG AbstractSaveEventListener:240 - executing insertions
11:17:43,051 DEBUG AbstractSaveEventListener:289 - executing identity-insert immediately
11:17:43,051 DEBUG AbstractEntityPersister:2030 - Inserting entity: edu.upmc.ccweb.purchasing.model.Item (native id)
11:17:43,051 DEBUG AbstractBatcher:358 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
11:17:43,051 DEBUG SQL:393 - insert into tbl_item (quantity, description, price) values (?, ?, ?)
11:17:43,051 DEBUG AbstractBatcher:476 - preparing statement
11:17:43,051 DEBUG AbstractEntityPersister:1905 - Dehydrating entity: [edu.upmc.ccweb.purchasing.model.Item#<null>]
11:17:43,051 DEBUG IntegerType:80 - binding '1' to parameter: 1
11:17:43,051 DEBUG StringType:80 - binding 'black s2000' to parameter: 2
11:17:43,051 DEBUG StringType:80 - binding 34000.00' to parameter: 3
11:17:43,083 DEBUG IdentifierGeneratorFactory:37 - Natively generated identity: 4
11:17:43,083 DEBUG AbstractBatcher:366 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
11:17:43,083 DEBUG AbstractBatcher:525 - closing statement
11:17:43,083 DEBUG Cascade:300 - done cascade ACTION_SAVE_UPDATE for collection: edu.upmc.ccweb.purchasing.model.PurchaseRequest.items
so there it is right there, it's getting cascaded. if i go and look in the items table, there's a row in there like expected. but the join table is blank so i can't get to it .. any ideas?? when does the join table get populated?