Property field not updated UNLESS 1st initialised [message #492475] |
Tue, 20 October 2009 14:56 |
Olu 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 |
|
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 |
Olu 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,
|
|
|
|
|
|
problems setting javaagent in glassfish v3 [message #643562 is a reply to message #496244] |
Tue, 07 December 2010 12:50 |
Aaqib 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.02635 seconds