Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Using Observable Lists within entity classes?
Using Observable Lists within entity classes? [message #516797] Thu, 25 February 2010 08:49 Go to next message
Olu  is currently offline Olu Friend
Messages: 29
Registered: October 2009
Junior Member
I have 2 entity classes which both have collections of each other's type in many-many config. something like the code below:-

@entity 
@Table(name = "A")
...
@JoinTable(name = "JOIN_TBL",
        joinColumns = @JoinColumn(name = "COL_ID"),
        inverseJoinColumns = @JoinColumn(name = "J_COL_ID"))
private Collection<B> BCollection;
...

and then

@entity
@Table(name = "B")
...
    @ManyToMany(mappedBy = "sembookingsCollection", cascade=CascadeType.ALL,fetch=FetchType.EAGER)
    private Collection<A> ACollection;
..

Within the application I bind ACollection to a JTable...

org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${selectedElement.ACollection}");
org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, eLProperty, detailTable);



The above is all pretty standard stuff and my JTable doesn't get updated after changes to ACollection.

I can see I an Observable wrapper around the ACollection might do the trick but Observable Lists are not supported in the JPA spec. for entity classes.

Setting fetchType to EAGER doesn't solve the problem (and perhaps it shouldn't).

Apart from observable lists I can't see how to update a list in real time. Does anyone have a solution to this issue?

many thanks,
Re: Using Observable Lists within entity classes? [message #516987 is a reply to message #516797] Thu, 25 February 2010 16:55 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Hello,

I'm not sure exactly, but it sounds like you are updating the ACollection but not also updating the BCollection. If so, the problem is that you are updating the non-owning side of a bidirectional relationship. Both sides need to be updated inorder to keep the cache insynch with what is in the database, but the owning side (the BCollection) actually controls what goes into the database.

Best Regards,
Chris
Re: Using Observable Lists within entity classes? [message #517010 is a reply to message #516987] Thu, 25 February 2010 17:38 Go to previous message
Olu  is currently offline Olu Friend
Messages: 29
Registered: October 2009
Junior Member
Hello Chris,

I sorted the problem.

Basically the application is stand alone using an application managed entity manager so I pass it around as a class parameter. (I wonder if there's a better way of doing this?)

However, in this particular class I declared a new entityManager (joys of using an IDE) and used that instead of using the manager passed in. I suspect this meant a new persistance context was created which masked the main context.

Now everything is working fine.

Depending how code is structured I gusess it's always possible to avoid the need for an observable list within an entity class declaration.

Thanks for replying,

Olu.

[Updated on: Thu, 25 February 2010 17:39]

Report message to a moderator

Previous Topic:Invalidation and JPA
Next Topic:OneToMany does not populate Foreign Key or null foreign key
Goto Forum:
  


Current Time: Tue Mar 19 14:06:12 GMT 2024

Powered by FUDForum. Page generated in 0.02897 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top