-->
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.  [ 4 posts ] 
Author Message
 Post subject: @OneToMany(cascade=ALL) does cascade but join table is blank
PostPosted: Tue Nov 14, 2006 12:20 pm 
Beginner
Beginner

Joined: Sat Aug 19, 2006 8:04 pm
Posts: 30
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?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 15, 2006 11:50 am 
Beginner
Beginner

Joined: Sat Aug 19, 2006 8:04 pm
Posts: 30
bump for some help


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 11, 2007 5:16 pm 
Newbie

Joined: Sat Mar 10, 2007 3:48 pm
Posts: 1
i dont know if you still need help for this problem, but i had the same right now and found my mistake:

i forgot to add the line

session.flush();

the entrys for the jointable were in the memory of the JVM and werent saved to the database. when u run this command, u enforce a synchronisation between the db and the memory of hibernate.
But i wondered, why the data is not saved, when i kill the session manually. Does anyone can enlighten this perhaps?


Top
 Profile  
 
 Post subject: Re:
PostPosted: Sat May 05, 2012 2:57 pm 
Newbie

Joined: Sat May 05, 2012 2:54 pm
Posts: 1
Yoghurt2k wrote:
i dont know if you still need help for this problem, but i had the same right now and found my mistake:

i forgot to add the line

session.flush();

the entrys for the jointable were in the memory of the JVM and werent saved to the database. when u run this command, u enforce a synchronisation between the db and the memory of hibernate.
But i wondered, why the data is not saved, when i kill the session manually. Does anyone can enlighten this perhaps?



Thanks Sir - you are a life saver :-D

Had the same problem and spend many hours looking for the answer in various forums. Your solution finally solved the problem.


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