|
|
|
gerogut
|
(This post was updated on )
Hi, I'm a begginer in this matter so I'm sorry if my questions are stupid.
I'm building a webapp to manage the books i have in my office. I have a book class which has the info I need and it has a Set<BookFile> which will store file associated to that info. That is, the actual pdf of the book, examples, etc. 1 - I declared the set with @OnToMany with a @JoinTable and @LazyCollection is that ok? It creates de DB ok and populates it with my sample data. 2- Then I have a booksearch.jsp which allowws me to search through the books and then shows me the list of books in books.jsp 3- If I click on a book it sends me to bookform.jsp which shows me book info in a form an I can update the info. 4- When I click on the "files" button it takes me to the bookfiles.jsp which is the list of files associated to that book, and then comes my PROBLEM, which I dont know how to resolve and maybe t comes from before. 5- when I add a book it adds it to the DB but it does not add the value to the joinTable so the file is not associated to the book. And i can't acces the value of the Book from bookFileFormController... Any suggestions, corrections, comments? THANK YOU. |
||||||||||||||||
|
ramzi khlil
|
You may need to specify cascade attribute.
Ramzi
On Thu, Nov 5, 2009 at 12:50 PM, gerogut <[hidden email]> wrote:
|
||||||||||||||||
|
gerogut
|
This is what I have annotated in BookFile set.
@OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}) @JoinTable(name = "book_file", joinColumns = {@JoinColumn(name="book_id")}, inverseJoinColumns = {@JoinColumn(name = "bookFile_id")}) @LazyCollection(value = LazyCollectionOption.FALSE) public Set<BookFile> getBookFiles() { return bookFiles; } Gero
|
||||
|
ramzi khlil
|
Can you describe the workflow.
How do you add BookFile to Book object ?
Ramzi
On Thu, Nov 5, 2009 at 2:57 PM, gerogut <[hidden email]> wrote:
|
||||||||||||||||
|
gerogut
|
|
||||||||||||||||
|
ramzi khlil
|
You can simply add your book object to the ModelAndView.
Use a Map to include the book.
Map objects = new HashMap();
objects.put("ParentBook", book);
objects.put("bookFileList",bookManager.get(book.getId()).getBookFiles());
ModelAndView().addObject("bookFileList", objects); On Thu, Nov 5, 2009 at 3:54 PM, gerogut <[hidden email]> wrote:
|
||||||||||||||||
|
ramzi khlil
|
Sorry I misunderstand you requirement,
A simple solution consists of creating a hidden field in BookFileList.jsp that holds the id of the book.
Ramzi
On Thu, Nov 5, 2009 at 4:13 PM, ramzi khlil <[hidden email]> wrote:
|
||||||||||||||||
|
oskarher
|
In reply to this post
by ramzi khlil
Some javascript/style in this post has been disabled (why?)
Hi, sorry if this list is not the correct place to ask this, but when I want to update a collection (insert or remove an item) hibernate first remove all items from database and then insert the items in the collection, I don't understand why. Someone knows something about this? Thanks a lot! |
||||||||||||||||
|
Dale Newfield
|
On Thu, Nov 5, 2009 at 4:29 PM, Oscar Rodriguez
<[hidden email]> wrote: > Hi, sorry if this list is not the correct place to ask this, but when I want > to update a collection (insert or remove an item) hibernate first remove all > items from database and then insert the items in the collection, I don't > understand why. Depends on how you update that collection. If you're replacing the List/Set/etc. with a new List/Set/etc. it doesn't have much choice. If you take the one with which your object was populated and call .add(), .remove(), etc on it there's a chance it can be smarter. -Dale --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
||||||||||||||||
|
oskarher
|
I just doing this:
ParentObj parent = dao.get(ParentObj.class, id); ChildObj child = new ChildObj(); child.setId(childId); parent.getChildCollection().remove(child); dao.save(parent); Thanks! ----- Original Message ----- From: "Dale Newfield" <[hidden email]> To: <[hidden email]> Sent: Thursday, November 05, 2009 6:38 PM Subject: Re: [appfuse-user] Hibernate collections On Thu, Nov 5, 2009 at 4:29 PM, Oscar Rodriguez <[hidden email]> wrote: > Hi, sorry if this list is not the correct place to ask this, but when I > want > to update a collection (insert or remove an item) hibernate first remove > all > items from database and then insert the items in the collection, I don't > understand why. Depends on how you update that collection. If you're replacing the List/Set/etc. with a new List/Set/etc. it doesn't have much choice. If you take the one with which your object was populated and call .add(), .remove(), etc on it there's a chance it can be smarter. -Dale --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] E-mail clasificado por el Idenfificador de Spam Inteligente. Para modificar la categoría clasificada acceda a su webmail Este mensaje ha sido verificado por el E-mail Protegido. Antivirus actualizado en 05/11/2009 / Versión: 0.95.2/9994 --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
||||||||||||||||
|
ramzi khlil
|
You are creating an new object.
Try to get a reference to the object from the list using its object and then run remove(yourobject).
Ramzi
On Thu, Nov 5, 2009 at 4:46 PM, Oscar Rodriguez <[hidden email]> wrote: I just doing this: |
||||||||||||||||
|
Wojciech Wąsowicz
|
In reply to this post
by gerogut
2009/11/5 gerogut <[hidden email]>:
> > > 4. When I click on a file, bookFileForm is displayed, the controller is > BookFileFormController and it has a different manager wich is > BookFileManager.(bookfileform.jsp) Here it's the problem, I can't get to > associate the file to the book because I don't know how to get the book > without an id. In this controller I only have the id of the bookFile. So, > answering you second question, I can't add BookFile to the Book object. > Maybe you need to add to BookFileController the BookManager bean, just the same way as BookFileManager is inserted .. Then you can get Book from BookManager .. just need book.id from request or bookFile .. regards Wojtek --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
||||||||||||||||
|
oskarher
|
In reply to this post
by ramzi khlil
Some javascript/style in this post has been disabled (why?)
I try, but always hibernate executes "delete all"
first.
Thanks anyway.
|
||||||||||||||||
|
gerogut
|
In reply to this post
by ramzi khlil
But I have the problem in the next step, when I go from BookFileList.jsp (actually called bookfiles.jsp which displays a list of files) to BookFileForm.jsp.
In BookFileList I have the list of bookFiles of a certain book, if I click on a line of the table(file) it takes me to bookfileform.html?id=# and there I can change the info of the current bookFile and even change the file. The id there is a bookFile id. BUT if I click on the button ADD from BookFileList it takes me to bookfileform.html and it doesn't associate that new file to the current book. Where do I have to add the bookFile? as soon as I click on add on bookfilelist or when I save changes on book file form? Do you need a little bit of code to help? I don't post it because it is quite long. Gero
|
||||||||||||||||
|
gerogut
|
In reply to this post
by Wojciech Wąsowicz
I have mi dispatcher-servlet like this
<bean id="bookFileFormController" class="com.code54.bookshelf.webapp.controller.BookFileFormController"> <property name="successView" value="redirect:bookfileform.html"/> <property name="bookFileManager" ref="bookFileManager"/> <property name="bookManager" ref="bookManager"/> </bean> the thing is I can't get the book id, how can y send the book from bookFileController to BookFileFormControler...
|
||||||||||||||||
|
gerogut
|
In reply to this post
by ramzi khlil
Ramzi I received an email where it said something about keeping book id along the process and adding the book id in the action associated with the add button. I read that in the preview but I can't find the post.
Did you delete it? can you post it again? thanks. Gero
|
||||||||||||||||
|
mraible
|
In reply to this post
by oskarher
As you might've seen on the thread below, if you're a Nabble user, you'll have to re-register with the new system. As they say in the thread below, the good news is it won't take long at all.
Matt On Fri, Nov 6, 2009 at 11:51 AM, Matt Raible <[hidden email]> wrote: I asked them to upgrade to Nabble 2 this morning. If this requires everyone to re-register, that's not good at all. |
||||||||||||||||
|
ramzi khlil
|
In reply to this post
by gerogut
Gero,
I didn't delete it.
Are you talking about this ?
You need to keep the book id along the process.
So you need to add the book id in the action associated with add button. When you clic on add button you should call this url bookfileform.html?Bookid=# Anothor solution, add a binder to book object and display the list of book in BookFileForm.jsp. Ramzi On Sun, Nov 8, 2009 at 3:31 PM, gerogut <[hidden email]> wrote:
|
||||||||||||||||
| Free Embeddable Forum Powered by Nabble | Help |