Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Property field not updated UNLESS 1st initialised(JPA technical question.....)
Property field not updated UNLESS 1st initialised [message #492475] Tue, 20 October 2009 14:56 Go to next message
Olu  is currently offline Olu Friend
Messages: 29
Registered: October 2009
Junior Member
Have a problem with property fields not being updated in the dB - am using eclipselink for ORM with JPA.

Have underlying dB in javadb with
tab 1
id (PK)
..

tab 2
..
NAME varchar
AGE int
FK-->id (tab 1)

Then have entitiy POJOs for each table with the FK in tab 2 annotated with joincol/many-1 annotations. Also have cascade type set to ALL for collection property in tab1 to hold tab 2 objects.

I create editor class in swing with property to hold newly created tab1 and tab 2 objects. The NAMEand AGE (for tab 2) are set via swing txt fields that have been bound to corrsponding entity properties.

I only persist the object which corresponds to tab 1 (cascadetype set to ALL) within the editor class.

The problem is I enter name and age values within the editor, but only the name value is updated in the datbase? HOWEVER, if I initialise the AGE value and change it within the editor it IS updated in the dB.

Likewise, if I initialise the AGE value in the tab 2 entity constructer to anything BUT NULL, all works fine.

In summary, the AGE property field for POJO represented by tab 2 only gets updated via binding IF it is initiliased to a non NULL value? Can anyone shed any light on this - tis a mystery to me.

thanks,

[Updated on: Wed, 21 October 2009 08:12]

Report message to a moderator

Re: Property field not updated UNLESS 1st initialised [message #492750 is a reply to message #492475] Wed, 21 October 2009 15:28 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Could you include the source code to the class, both the one that works, and the one that does not.

Note, that EclipseLink will only update properties that changed, so if you set the age to its current value, you will not see it in the update.

Are you using weaving/agent? Try disabling weaving, or enabling if you are not using it, does it work?


James : Wiki : Book : Blog : Twitter
Re: Property field not updated UNLESS 1st initialised [message #493075 is a reply to message #492475] Fri, 23 October 2009 00:47 Go to previous messageGo to next message
Olu  is currently offline Olu Friend
Messages: 29
Registered: October 2009
Junior Member
Relevant code snippets below...

=========Entity classes ===============

public class Customers implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID")
    private Integer id;
    ...
    ...
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "custId")
    private List<Boonga> boongaCollection;

...
...


public class Boonga implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "B_ID")
    private Integer bId;
    @Column(name = "B_NAME")
    private String bName;
    @Column(name = "B_AGE")
    private Integer bAge;

    @JoinColumn(name = "CUST_ID", referencedColumnName = "ID")
    @ManyToOne
    private Customers custId;

...
...
    //setters for Boonga entity......
    public void setBName(String bName) {
        this.bName = bName;
    }


    public void setBAge(Integer bAge) {
        Integer oldbAge = this.bAge;
        this.bAge = bAge;
        //added later to try and solve issue
        changeSupport.firePropertyChange("bAge", oldbAge, bAge); 
    }


=====CustomerEditor Class
public class CustomerEditor extends javax.swing.JDialog {

     protected Customers currentRecord;
     protected Boonga currentBoonga;

     init()..{
     ...
     binding =  

org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.

READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${currentBoonga.BAge}"), 

jFormattedTextField3, org.jdesktop.beansbinding.BeanProperty.create("value"));
        bindingGroup.addBinding(binding);
     ...
     ...

        binding = 

org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.

READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${currentBoonga.BName}"), jTextField8, 

org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

======Main app class...
...
...
  public void newRecord() {
        Customers c = new Customers();
        Boonga boo = new Boonga();        
        Collection<Boonga> booc = new LinkedList<Boonga>();
        c.setBoongaCollection((List)booc);

        boo.setCustId(c);
        booc.add(boo);
        entityManager.persist(c);
        list.add(c);
        int row = masterTable.getRowCount() - 1;
        masterTable.setRowSelectionInterval(row, row);
        masterTable.scrollRectToVisible(masterTable.getCellRect(row, 0, true));
        setSaveNeeded(true);
        
        JFrame mainFrame = CustomerRecordsApp.getApplication().getMainFrame();
        CustomerEditor ce = new CustomerEditor(mainFrame, false);
        ce.setCurrentRecord(c);
        ce.setCurrentBoonga(boo);

        ce.setVisible(true);
        
        if (ce.isCustomerConfirmed()) {
            save().run();
        } else {
            refresh().run()
        ...
        ...


You'll see Name and Age are part of the same entity - BName get's updated via binding and Age doesn't unless first initialised either in the constructor or by using it's setter upon creation.

thanks,
Re: Property field not updated UNLESS 1st initialised [message #493546 is a reply to message #492475] Mon, 26 October 2009 18:24 Go to previous messageGo to next message
Olu  is currently offline Olu Friend
Messages: 29
Registered: October 2009
Junior Member
ok, having prblems trying to switch weaving on......

persistence xml is

...
    <properties>
  ...
               <property      name="eclipselink.weaving"     value="true"    />
...
    </properties>


build is ok but get run time error as below:-

26-Oct-2009 18:11:49 org.jdesktop.application.Application$1 run
SEVERE: Application class customerrecords2.CustomerRecordsApp failed to launch
Local Exception Stack: 
Exception [EclipseLink-30005] (Eclipse Persistence Services - 1.1.2.v20090612-r4475): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: sun.misc.Launcher$AppClassLoader@11b86e7
Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28022] (Eclipse Persistence Services - 1.1.2.v20090612-r4475): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Value [true] for the property [eclipselink.weaving] is incorrect when global instrumentation is null, value should either be null or false.
        at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:121)
        at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:133)
        at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:67)
        at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
        at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
        at customerrecords2.CustomerRecordsView.initComponents(CustomerRecordsView.java:436)
        at customerrecords2.CustomerRecordsView.<init>(CustomerRecordsView.java:48)
        at customerrecords2.CustomerRecordsApp.startup(CustomerRecordsApp.java:19)
        at org.jdesktop.application.Application$1.run(Application.java:171)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)


Anyone spot what I've done wrong here...?

thanks,
Re: Property field not updated UNLESS 1st initialised [message #493552 is a reply to message #493546] Mon, 26 October 2009 19:16 Go to previous messageGo to next message
Tom Eugelink is currently offline Tom EugelinkFriend
Messages: 817
Registered: July 2009
Senior Member
I had something similar a while back; turns out the property is totally irrelevant, you only need to specify the -javaagent:eclipselink.jar at the command prompt.

Tom




Olu wrote:
> ok, having prblems trying to switch weaving on......
>
> persistence xml is
>
> ..
> <properties>
> ...
> <property name="eclipselink.weaving"
> value="true" />
> ..
> </properties>
>
>
> build is ok but get run time error as below:-
>
>
> 26-Oct-2009 18:11:49 org.jdesktop.application.Application$1 run
> SEVERE: Application class customerrecords2.CustomerRecordsApp failed to
> launch
> Local Exception Stack: Exception [EclipseLink-30005] (Eclipse
> Persistence Services - 1.1.2.v20090612-r4475):
> org.eclipse.persistence.exceptions.PersistenceUnitLoadingExc eption
> Exception Description: An exception was thrown while searching for
> persistence archives with ClassLoader:
> sun.misc.Launcher$AppClassLoader@11b86e7
> Internal Exception: javax.persistence.PersistenceException: Exception
> [EclipseLink-28022] (Eclipse Persistence Services -
> 1.1.2.v20090612-r4475):
> org.eclipse.persistence.exceptions.EntityManagerSetupExcepti on
> Exception Description: Value [true] for the property
> [eclipselink.weaving] is incorrect when global instrumentation is null,
> value should either be null or false.
> at
> org.eclipse.persistence.exceptions.PersistenceUnitLoadingExc eption.exceptionSearchingForPersistenceResources(Persistence UnitLoadingException.java:121)
>
> at
> org.eclipse.persistence.jpa.PersistenceProvider.createEntity ManagerFactory(PersistenceProvider.java:133)
>
> at
> org.eclipse.persistence.jpa.PersistenceProvider.createEntity ManagerFactory(PersistenceProvider.java:67)
>
> at
> javax.persistence.Persistence.createEntityManagerFactory(Unk nown Source)
> at
> javax.persistence.Persistence.createEntityManagerFactory(Unk nown Source)
> at
> customerrecords2.CustomerRecordsView.initComponents(Customer RecordsView.java:436)
>
> at
> customerrecords2.CustomerRecordsView.<init>(CustomerRecordsView.java:48)
> at
> customerrecords2.CustomerRecordsApp.startup(CustomerRecordsA pp.java:19)
> at org.jdesktop.application.Application$1.run(Application.java: 171)
> at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java :209)
> at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
> at
> java.awt.EventDispatchThread.pumpOneEventForFilters(EventDis patchThread.java:269)
>
> at
> java.awt.EventDispatchThread.pumpEventsForFilter(EventDispat chThread.java:184)
>
> at
> java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDis patchThread.java:174)
>
> at
> java.awt.EventDispatchThread.pumpEvents(EventDispatchThread. java:169)
> at
> java.awt.EventDispatchThread.pumpEvents(EventDispatchThread. java:161)
> at java.awt.EventDispatchThread.run(EventDispatchThread.java:12 2)
>
>
> Anyone spot what I've done wrong here...?
>
> thanks,
Re: Property field not updated UNLESS 1st initialised [message #496244 is a reply to message #492475] Mon, 09 November 2009 13:12 Go to previous messageGo to next message
Olu  is currently offline Olu Friend
Messages: 29
Registered: October 2009
Junior Member
Thanks Tom - that worked.

The problem was also due to the fact I was using a Jformatted text field rather than a text field and using Integer.Parseint to retrieve the number value.
problems setting javaagent in glassfish v3 [message #643562 is a reply to message #496244] Tue, 07 December 2010 12:50 Go to previous messageGo to next message
Aaqib  is currently offline Aaqib Friend
Messages: 4
Registered: December 2010
Junior Member
Hi everybody,

My problem is that after i give the JVm option of -javaagent:eclipselink-2.0.0.jar, by giving the full directory path of the jar file,,

the server fails to start. because it cannot find the class PersistenceUnitInfo in the javax.persistence.spi package from the eclipselink jar.

i have checked and found that the class is not present in the spi package.

do I have to use a different eclipselink jar file to be used as agent..

I need help with this.


My basic problem is that I get a communication failure message while tryling to load entities which have sub lists of other entities. it is not working with fetch type of eager or lazy. where as it works for other entities. one entity is giving me this trouble.

then i did some search and found out about the following in the persistence.xml file
<property name="eclipselink.weaving" value="true"/>
<property name="eclipselink.weaving.lazy" value="true"/>

but then the message occured that
Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-28022] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.EntityManagerSetupExcepti on
Exception Description:Value [true] for the property [eclipselink.weaving] is incorrect when global instrumentation is null, value should either be null or false.

then i came to this forum and read toms reply to turn javaagent on.

Awaiting help.

regards
Aaqib

[Updated on: Tue, 07 December 2010 13:03]

Report message to a moderator

Re: problems setting javaagent in glassfish v3 [message #643582 is a reply to message #643562] Tue, 07 December 2010 14:24 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Hello Aaqib,

The EclipseLink jar only includes the few classes it has a dependency on as it can run in a non-JPA environment. You must have everything on the classpath before it can run, and you seem to be missing the JPA javax.persistence jar.

You can test this by turning weaving off - setting the eclipselink.weaving property to false. Weaving is not required for JPA to work, it is only required to take advantage of lazy hints on 1:1 relationships, and allow other optimizations to occur.

A simple tutorial is available here:
http://www.vogella.de/articles/JavaPersistenceAPI/article.ht ml
And the docs describing weaving and links for the various options here:
http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_ (ELUG)#How_to_Use_the_Persistence_Unit_Properties_for_Custom ization_and_Validation

Best Regards,
Chris
Previous Topic:JAXBContextFactory Not Found
Next Topic:Removing and entity with and @JoinTable
Goto Forum:
  


Current Time: Fri Apr 19 20:22:18 GMT 2024

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

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

Back to the top