@ManyToMany PersistentSet

23 views
Skip to first unread message

José Coelho

unread,
Feb 18, 2011, 11:32:36 AM2/18/11
to dpHibernate
Hi all...
Firstly, sorry for my bad english!

I'm having problems with @ManyToMany associations using dpHibernate.
All my associations are deleted after save an item that LAZY objects
are not loaded on FLEX...

Let me explain the problem with examples. ( the code will not compile)
*in this example id, getters/setters and details are skipped

CURRENT SCENARIO:

I have an entity called File, that can be associated with any Entity
from my project.

class File {
String name;
}

When I need to associate File(s) with an Entity, I create a relation
ManyToMany unidirectional like explained above:


class Author implements FileContainer {
String name;

@ManyToMany(fetch=LAZY)
@JoinTable(name="author_file",joinColumns={ author_id,
inverseJoinColumns=file_id } //simplified
Set<File> files;

}

class Book implements FileContainer {
String name;

@ManyToMany(fetch=LAZY)
@JoinTable(name="book_file",joinColumns={ "book_id",
inverseJoinColumns="file_id" }
Set<File> files;

}

... with this and a generic file service, I can associate files with
any entity of my project, on a simple way... its very nice! :)
(one file could be assciated with more than one entity)

THE PROBLEM:

1. Load one of these entities that have association with one or more
Files,
2. send it to Flex,
3. edit something. (not loading any file)
4. return to Java
5. and save. (merge or saveOrUpdate)

RESULT: All relations with that entity are removed.

INVESTIGATIONS:

- When an association is @OneToMany theres no problem, all relations
are maintened
- When @OneToMany after deserialize, the value of SET is an empty
HashSet, but on @ManyToMany the value of set is Null.
- I'm forced the value of Set to an empty HashSet like @OneToMany, but
thats no take effect
- I tried to change all Cascade types from hibernate without success
- When you load an entity with Files on Java, do not start LAZY of
files and save that (without sending to flex)... All relations are
maintened.
- When load one of that entities on JAVA, before send to FLEX the Set
has the type of a PersistentSet, but when that return to JAVA the Set
of Files has NULL value.

Do you know what to do for maintain ManyToMany the associations
without forcing load of all files on Flex client site?

Thanks a lot.


Umut

unread,
Feb 18, 2011, 2:28:31 PM2/18/11
to dpHibernate
Hi Jose,

I assume you send the entity from flex to server as a parameter.

I would suggest sending id's of the entity and the file to be
associated to the server and doing the changes on the server side then
save.
When using dphibernate I got all kinds of problems whenever I tried to
send an entity as service parameter.

A second and maybe a little harder way is to use entity.save(),
entity.deleteRecord() methods directly from flex (without sending the
entity as service parameter. Actually without using any service at
all) You can look at the lazyoverflow example for the implementation.
entity.save() (or deleteRecord for that matter) only sends proxy
information adn changes made to the entity to the server as parameters
so it wouldn't cause trouble like using services.
Reply all
Reply to author
Forward
0 new messages