Hi,
Here is the entity definition. A simplified test case passed in POJO
environment. But the error was happen in EJB container(WLS).
BaseEntity
@MappedSuperclass
public abstract class BaseEntity implements Serializable {
private static final String CLASS_NAME = BaseEntity.class.getName();
private static Logger _logger = Logger.getLogger(CLASS_NAME);
@Id
@Column(name = "id")
@TableGenerator(name = "primary_key_generator", table = "GLOBAL_KEY",
pkColumnName = "PK_NAME", valueColumnName = "SEQUENCE", pkColumnValue =
"TMS")
@GeneratedValue(strategy = GenerationType.TABLE, generator =
"primary_key_generator")
protected Integer _id;
@Version
@Column(name = "update_version")
private Integer _version;
@Column(name = "created_by")
private String _createdBy;
@Column(name = "create_date")
private Timestamp _createDate;
@Column(name = "updated_by")
private String _updatedBy;
@Column(name = "update_date")
private Timestamp _updateDate;
/**
* Default constructor - used ONLY for new entities that have not been
previously created
*/
protected BaseEntity() {
super();
}
/**
* Constructor to create an entity for existing entities.
*
* @param id refers to an existing entity identifier
* @throws InvalidPrimaryKeyException if a null value is passed in
*/
protected BaseEntity(Integer id) throws InvalidPrimaryKeyException {
if(id == null) {
throw new InvalidPrimaryKeyException(
UtilServiceLocator.getInvalidPrimaryKeyExceptionContent(
CLASS_NAME, "BaseEntity",
ErrorDefinitionPkConstants.INVALID_PRIMARY_KEY));
}
this._id = id;
}
/**
* @return returns the primaryKey
*/
public Integer getId() {
return _id;
}
/**
* @return created_by
*/
public String getCreatedBy() {
return this._createdBy;
}
/**
* Set created_by
*
* @param createdBy
*/
public void setCreatedBy(String createdBy) {
this._createdBy = createdBy;
}
/**
* @return create_date
*/
public Timestamp getCreateDate() {
return this._createDate;
}
/**
* Set create_date
*
* @param createDate
*/
public void setCreateDate(Timestamp createDate) {
this._createDate = createDate;
}
/**
* @return updated_by
*/
public String getUpdatedBy() {
return this._updatedBy;
}
/**
* Set updated_by
*
* @param updatedBy
*/
public void setUpdatedBy(String updatedBy) {
this._updatedBy = updatedBy;
}
/**
* @return update_date
*/
public Timestamp getUpdateDate() {
return this._updateDate;
}
/**
* Set update_date
*
* @param updateDate
*/
public void setUpdateDate(Timestamp updateDate) {
this._updateDate = updateDate;
}
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
boolean equals = false;
if(_id == null) {
equals = super.equals(obj);
} else {
if(this.getClass().isInstance(obj)) {
equals = _id.equals(((BaseEntity)obj)._id);
}
}
return equals;
}
/**
* Returns a hash code value for the primary key of the bean.
*
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
int hashcode = 0;
if(_id == null) {
hashcode = super.hashCode();
} else {
hashcode = _id.hashCode();
}
return hashcode;
}
/**
* Set the create_date and created_by after an entity is persisted
*
* @param entity
*/
@PrePersist
public void updateCreateAuditColumns() {
setCreateDate(new Timestamp(System.currentTimeMillis()));
setCreatedBy("test"); // need to resolve this.
}
/**
* Set the update_date and updated_by after an entity is updated
*
* @param entity The updating entity.
*/
@PreUpdate
public void updateUpdateAuditColumns() {
setUpdateDate(new Timestamp(System.currentTimeMillis()));
setUpdatedBy("test");
}
}
Event Entity
@Entity
@Table(name = "event")
@NamedQueries( {
@NamedQuery(name = "EventEntity.findByOwner", query = "SELECT i FROM
EventEntity i WHERE i._statusCid = 1140 "
+ "AND _fromClassId =: fromClassID AND _fromId =: fromId"),
@NamedQuery(name = "EventEntity.findAllByOwner", query = "SELECT i FROM
EventEntity i WHERE _fromClassId =: fromClassID AND _fromId =: fromId")})
public class EventEntity extends BaseEntity {
@Column(name = "from_class_id")
private Integer _fromClassId;
@Column(name = "type_cid")
private Integer _typeCid;
@Column(name = "from_id")
private Integer _fromId;
@Column(name = "status_cid")
private Integer _statusCid;
@Column(name = "date_time")
private Date _dateTime;
/**
* Get all the entries in the event table where status_cid = 1140 and
from_class_id = ? and from_id = ?
*
* @param em
* @param fromId
* @param fromClassId
* @return - A collection of <code>EventEntity</code>'s
*/
public static Collection<EventEntity> findByOwner(EntityManager em, int
typeCid, int fromId, int fromClassId) {
Query query = em.createNamedQuery("EventEntity.findByOwner");
query.setParameter(1, fromId);
query.setParameter(2, fromClassId);
Collection<EventEntity> eventEntities = query.getResultList();
return eventEntities;
}
/**
* Get all the entries in the event table where from_class_id = ? and
from_id = ?, with no qualifier on the
* status_cid column
*
* @param em
* @param fromId
* @param fromClassId
* @return - A collection of <code>EventEntity</code>'s
*/
public static Collection<EventEntity> findAllByOwner(EntityManager em,
int typeCid, int fromId, int fromClassId) {
Query query = em.createNamedQuery("EventEntity.findAllByOwner");
query.setParameter(1, fromId);
query.setParameter(2, fromClassId);
Collection<EventEntity> eventEntities = query.getResultList();
return eventEntities;
}
public Integer getFromClassId() {
return _fromClassId;
}
public void setFromClassId(Integer classId) {
_fromClassId = classId;
}
public Integer getTypeCid() {
return _typeCid;
}
public void setTypeCid(Integer cid) {
_typeCid = cid;
}
public Integer getFromId() {
return _fromId;
}
public void setFromId(Integer id) {
_fromId = id;
}
public Integer getStatusCid() {
return _statusCid;
}
public void setStatusCid(Integer cid) {
_statusCid = cid;
}
public Date getDateTime() {
return _dateTime;
}
public void setDateTime(Date time) {
_dateTime = time;
}
}
On 9/18/07, Patrick Linskey <[EMAIL PROTECTED]> wrote:
>
> Can you post the definitions for both classes in the hierarchy please?
>
> -Patrick
>
> On 9/18/07, Gene Woo <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > Absolutely not. Because I only exposed this private field to a getting
> > method. So it's no possible to modify this value from outside of the
> class.
> >
> > BTW, this field is declared in Super class. Only these two entities met
> the
> > problem I described. The rest of them do not have such issue.
> >
> > Also, the error always comes with a optimistic lock error. But only one
> > Session Bean is working on these entities.
> >
> > Thanks,
> > Gene.
> >
> >
> > On 9/18/07, Patrick Linskey <[EMAIL PROTECTED]> wrote:
> > >
> > > > So far, my understanding on setting of the version field is a
> qualified
> > > > field(Integer, Long or DateType) with annotation @Version. Is this
> the
> > > one
> > > > you mentioned as manually setting?
> > >
> > > There is (presumably) some field in your object that is marked as
> > > @Version. Are you assigning a value to that field?
> > >
> > > -Patrick
> > >
> > > On 9/17/07, Gene Woo <[EMAIL PROTECTED]> wrote:
> > > > Hi,
> > > >
> > > > I have no idea about that "manually setting the version field in
> your
> > > > application".
> > > >
> > > > So far, my understanding on setting of the version field is a
> qualified
> > > > field(Integer, Long or DateType) with annotation @Version. Is this
> the
> > > one
> > > > you mentioned as manually setting?
> > > >
> > > > Thanks,
> > > >
> > > > Gene.
> > > >
> > > > On 9/18/07, Patrick Linskey <[EMAIL PROTECTED]> wrote:
> > > > >
> > > > > Hi,
> > > > >
> > > > > Are you manually setting the version field in your application?
> > > > >
> > > > > -Patrick
> > > > >
> > > > > On 9/17/07, Gene Woo <[EMAIL PROTECTED]> wrote:
> > > > > > Hi,
> > > > > >
> > > > > > I got the following error messages from application server. I am
> > > very
> > > > > > confused on that. Because this is an isolated entity without any
> > > > > > relationship to the rest of entities.
> > > > > >
> > > > > > <4|true|0.9.7>
> org.apache.openjpa.persistence.InvalidStateException:
> > > > > Attempt
> > > > > > to set column "event.update_version" to two different values:
> (class
> > > > > > java.lang.Integer)"2", (class java.lang.Integer)"3" This can
> occur
> > > when
> > > > > you
> > > > > > fail to set both sides of a two-sided relation between objects,
> or
> > > when
> > > > > you
> > > > > > map different fields to the same column, but you do not keep the
> > > values
> > > > > of
> > > > > > these fields in synch.
> > > > > >
> > > > > > Note: This update_version is a mapped-super class's
> property: @
> > > > > > [EMAIL PROTECTED](name = "update_version") private Integer
> _version;
> > > > > >
> > > > > > And I found the code only performed query and new/persist
> object.
> > > Not
> > > > > intent
> > > > > > to update or merge object.
> > > > > >
> > > > > > The error was found before perform query. As you know, system
> will
> > > flush
> > > > > > before query. Here is the stack trace:
> > > > > >
> > > > > > at org.apache.openjpa.jdbc.sql.PrimaryRow.setObject(
> > > > > PrimaryRow.java
> > > > > > :335)
> > > > > > at org.apache.openjpa.jdbc.sql.RowImpl.setObject(
> > > RowImpl.java
> > > > > :501)
> > > > > > at
> > > > > kodo.jdbc.meta.strats.ColumnPerLockGroupVersionStrategy.update(
> > > > > > ColumnPerLockGroupVersionStrategy.java:166)
> > > > > > at org.apache.openjpa.jdbc.meta.Version.update(
> Version.java
> > > :294)
> > > > > > at
> > > > > >
> > > org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.updateIndicators(
> > > > > > AbstractUpdateManager.java:308)
> > > > > > at
> > > org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.update(
> > > > > > AbstractUpdateManager.java:291)
> > > > > > at
> > > > > >
> > >
> org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.populateRowManager(
> > > > > > AbstractUpdateManager.java:149)
> > > > > > at
> > > org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(
> > > > > > AbstractUpdateManager.java:82)
> > > > > > at
> > > org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(
> > > > > > AbstractUpdateManager.java:69)
> > > > > > at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush
> (
> > > > > > JDBCStoreManager.java:511)
> > > > > > at
> org.apache.openjpa.kernel.DelegatingStoreManager.flush(
> > > > > > DelegatingStoreManager.java:127)
> > > > > > at
> org.apache.openjpa.datacache.DataCacheStoreManager.flush(
> > > > > > DataCacheStoreManager.java:506)
> > > > > > at
> org.apache.openjpa.kernel.DelegatingStoreManager.flush(
> > > > > > DelegatingStoreManager.java:127)
> > > > > > at org.apache.openjpa.kernel.BrokerImpl.flush(
> > > BrokerImpl.java
> > > > > :1970)
> > > > > > at org.apache.openjpa.kernel.BrokerImpl.flushSafe(
> > > > > BrokerImpl.java
> > > > > > :1868)
> > > > > > at org.apache.openjpa.kernel.BrokerImpl.flush(
> > > BrokerImpl.java
> > > > > :1639)
> > > > > > at org.apache.openjpa.kernel.QueryImpl.isInMemory(
> > > QueryImpl.java
> > > > > > :948)
> > > > > > at org.apache.openjpa.kernel.QueryImpl.execute(
> > > QueryImpl.java
> > > > > :782)
> > > > > > at org.apache.openjpa.kernel.QueryImpl.execute(
> > > QueryImpl.java
> > > > > :761)
> > > > > > at org.apache.openjpa.kernel.DelegatingQuery.execute(
> > > > > > DelegatingQuery.java:528)
> > > > > > at org.apache.openjpa.persistence.QueryImpl.execute(
> > > > > QueryImpl.java
> > > > > > :222)
> > > > > > at
> org.apache.openjpa.persistence.QueryImpl.getSingleResult(
> > > > > > QueryImpl.java:282)
> > > > > >
> > > > > > --
> > > > > > Best Regards,
> > > > > >
> > > > > > Gene Wu
> > > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Patrick Linskey
> > > > > 202 669 5907
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Best Regards,
> > > >
> > > > Gene Woo
> > > >
> > >
> > >
> > > --
> > > Patrick Linskey
> > > 202 669 5907
> > >
> >
> >
> >
> > --
> > Best Regards,
> >
> > Gene Woo
> >
>
>
> --
> Patrick Linskey
> 202 669 5907
>
--
Best Regards,
Gene Woo