| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| I'm using OpenJPA in Geronimo 2.1.3 and I have a timestamp column in a MySQL database, and even though the data in the table is right, every time I query the entity it returns 'null' instead of the timestamp data. Following is my entity: package com.pubint.ejb.entity; import java.io.Serializable; import java.sql.Timestamp; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.OneToOne; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; import javax.xml.bind.annotation.XmlType; @Entity @Table(name="compAttribValue") @XmlRootElement(name="currentValue") @XmlType(propOrder = {}) @XmlAccessorType(XmlAccessType.PROPERTY) public class CompAttribValue implements Serializable { private static final long serialVersionUID = 1L; private long id; private long parentID; private long valueID; private String valueData; private Timestamp valueChangeDate; private AttribValue value; public CompAttribValue() { } @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name="id") @XmlAttribute(name="id") public long getId() { return id; } public void setId(long id) { this.id = id; } @Column(name="xCAID") @XmlTransient public long getParentID() { return parentID; } public void setParentID(long id) { parentID = id; } @Column(name="valueID") @XmlAttribute(name="valueID") public long getValueID() { return valueID; } public void setValueID(long valueID) { this.valueID = valueID; } @Column(name="valueData") @XmlTransient public String getVData() { return valueData; } public void setVData(String valueData) { this.valueData = valueData; } @Transient @XmlElement(name="valueData") public String getValueData() { String returnValue; if (getValueID() != 0) { returnValue = getValue().getValueData(); } else { returnValue = getVData(); } return returnValue; } public void setValueData(String data) { setVData(data); } @Column(name="valueChanged") @Temporal(TemporalType.TIMESTAMP) public Timestamp getValueChangeDate() { return valueChangeDate; } public void setValueChangeDate(Timestamp date) { // } @OneToOne(fetch=FetchType.EAGER) @JoinColumn(name="valueID") public AttribValue getValue() { return value; } public void setValue(AttribValue value) { this.value = value; } } Anyone know what could help? Thanks, Scott |
|
#2
| |||
| |||
| Scott, Seems a bit too obvious, but could it be because your setter method is null? public void setValueChangeDate(Timestamp date) { // } Kevin On Thu, Oct 30, 2008 at 3:20 PM, Scott Mitchell <SMitchell-+7+0ccTrR5fQT0dZR+AlfA@public.gmane.org>wrote: > > I'm using OpenJPA in Geronimo 2.1.3 and I have a timestamp column in a > MySQL database, and even though the data in the table is right, every time > I query the entity it returns 'null' instead of the timestamp data. > Following is my entity: > > package com.pubint.ejb.entity; > > import java.io.Serializable; > import java.sql.Timestamp; > > import javax.persistence.Column; > import javax.persistence.Entity; > import javax.persistence.FetchType; > import javax.persistence.GeneratedValue; > import javax.persistence.GenerationType; > import javax.persistence.Id; > import javax.persistence.JoinColumn; > import javax.persistence.OneToOne; > import javax.persistence.Table; > import javax.persistence.Temporal; > import javax.persistence.TemporalType; > import javax.persistence.Transient; > import javax.xml.bind.annotation.XmlAccessType; > import javax.xml.bind.annotation.XmlAccessorType; > import javax.xml.bind.annotation.XmlAttribute; > import javax.xml.bind.annotation.XmlElement; > import javax.xml.bind.annotation.XmlRootElement; > import javax.xml.bind.annotation.XmlTransient; > import javax.xml.bind.annotation.XmlType; > > > @Entity > @Table(name="compAttribValue") > @XmlRootElement(name="currentValue") > @XmlType(propOrder = {}) > @XmlAccessorType(XmlAccessType.PROPERTY) > public class CompAttribValue implements Serializable { > private static final long serialVersionUID = 1L; > > private long id; > private long parentID; > > private long valueID; > private String valueData; > > private Timestamp valueChangeDate; > > private AttribValue value; > > public CompAttribValue() { > > } > > @Id > @GeneratedValue(strategy = GenerationType.IDENTITY) > @Column(name="id") > @XmlAttribute(name="id") > public long getId() { > return id; > } > > public void setId(long id) { > this.id = id; > } > > @Column(name="xCAID") > @XmlTransient > public long getParentID() { > return parentID; > } > > public void setParentID(long id) { > parentID = id; > } > > @Column(name="valueID") > @XmlAttribute(name="valueID") > public long getValueID() { > return valueID; > } > > public void setValueID(long valueID) { > this.valueID = valueID; > } > > @Column(name="valueData") > @XmlTransient > public String getVData() { > return valueData; > } > > public void setVData(String valueData) { > this.valueData = valueData; > } > > @Transient > @XmlElement(name="valueData") > public String getValueData() { > String returnValue; > > if (getValueID() != 0) { > returnValue = getValue().getValueData(); > } else { > returnValue = getVData(); > } > > return returnValue; > } > > public void setValueData(String data) { > setVData(data); > } > > @Column(name="valueChanged") > @Temporal(TemporalType.TIMESTAMP) > public Timestamp getValueChangeDate() { > return valueChangeDate; > } > > public void setValueChangeDate(Timestamp date) { > // > } > > @OneToOne(fetch=FetchType.EAGER) > @JoinColumn(name="valueID") > public AttribValue getValue() { > return value; > } > > public void setValue(AttribValue value) { > this.value = value; > } > } > > Anyone know what could help? > > Thanks, > Scott > > |
|
#3
| |||
| |||
| The following code seems to be the cause: > public void setValueChangeDate(Timestamp date) { > // > } How about the following instead? public void setValueChangeDate(Timestamp date) { this.valueChangeDate = date; } -- View this message in context: http://n2.nabble.com/Timestamp-alway...6p1400376.html Sent from the OpenJPA Users mailing list archive at Nabble.com. |
|
#4
| |||
| |||
| The Timestamp type field in MySQL is updated automatically whenever the record is touched, so it doesn't even need a set method, but if I don't have one it complains on deployment. Its not the set that is giving me issues but the get. In the database, none of the timestamp fields are null. -Scott Pinaki Poddar <ppoddar@apache.o rg> To users-8spYzHhHo/jWgOoZo4XcuR2eb7JE58TQ@public.gmane.org 10/30/2008 03:29 cc PM Subject Re: Timestamp always returns null Please respond to users-8spYzHhHo/iLdNgSkpkn4g@public.gmane.org che.org The following code seems to be the cause: > public void setValueChangeDate(Timestamp date) { > // > } How about the following instead? public void setValueChangeDate(Timestamp date) { this.valueChangeDate = date; } -- View this message in context: http://n2.nabble.com/Timestamp-alway...6p1400376.html Sent from the OpenJPA Users mailing list archive at Nabble.com. |
|
#5
| |||
| |||
| NEVERMIND! It does work now! Thank you SO MUCH. This was too simple for me to be stuck on for so long! -Scott Pinaki Poddar <ppoddar@apache.o rg> To users-8spYzHhHo/jWgOoZo4XcuR2eb7JE58TQ@public.gmane.org 10/30/2008 03:29 cc PM Subject Re: Timestamp always returns null Please respond to users-8spYzHhHo/iLdNgSkpkn4g@public.gmane.org che.org The following code seems to be the cause: > public void setValueChangeDate(Timestamp date) { > // > } How about the following instead? public void setValueChangeDate(Timestamp date) { this.valueChangeDate = date; } -- View this message in context: http://n2.nabble.com/Timestamp-alway...6p1400376.html Sent from the OpenJPA Users mailing list archive at Nabble.com. |
|
#6
| |||
| |||
| Scott Mitchell-2 wrote: > > NEVERMIND! It does work now! > > Thank you SO MUCH. This was too simple for me to be stuck on for so long! > > While annotations use property access mode (as opposed to field access) -- OpenJPA will invoke the setter to set the value of a field on a Java instance. So even if the corresponding column of MySQL database had a value, the value was not getting set on the in-memory instance because the setter method was a no-op. -- View this message in context: http://n2.nabble.com/Timestamp-alway...6p1400454.html Sent from the OpenJPA Users mailing list archive at Nabble.com. |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.