I have an abstract Entity class with abstract getters/setters that should not be persisted. I have marked these methods with @Transient on both the abstract Entity and all concrete Entity classes extending the abstract class, yet Toplink is persisting these fields.
Here are the relevant classes:
public abstract class AbstractEntity implements Serializable {
public abstract Long getId();
}
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public abstract class EntityOrdering<O extends AbstractEntity, N extends AbstractEntity> extends AbstractEntity {
private Long id;
private Integer positionIndex;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Column(precision=2)
public Integer getPositionIndex() {
return positionIndex;
}
public void setPositionIndex(Integer positionIndex) {
this.positionIndex = positionIndex;
}
@Transient
public abstract O getOwning();
@Transient
public abstract void setOwning(O owning);
@Transient
public abstract N getNonOwning();
@Transient
public abstract void setNonOwning(N nonOwning);
}
@Entity
public class TaxableOrdering extends EntityOrdering<TaxTypeDetail, Taxable> {
private Taxable taxable;
private TaxTypeDetail taxTypeDetail;
@Transient
public Taxable getNonOwning() {
return getTaxable();
}
public void setNonOwning(Taxable nonOwning) {
setTaxable(nonOwning);
}
@Transient
public TaxTypeDetail getOwning() {
return getTaxTypeDetail();
}
public void setOwning(TaxTypeDetail owning) {
setTaxTypeDetail(owning);
}
/* ==================== RELATIONSHIPS ==================== */
@ManyToOne
public Taxable getTaxable() {
return taxable;
}
public void setTaxable(Taxable taxable) {
this.taxable = taxable;
}
@ManyToOne
public TaxTypeDetail getTaxTypeDetail() {
return taxTypeDetail;
}
public void setTaxTypeDetail(TaxTypeDetail taxTypeDetail) {
this.taxTypeDetail = taxTypeDetail;
}
}
That code results in:
mysql> show columns from entityordering;
+---------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| ID | bigint(20) | NO | PRI | | |
| DTYPE | varchar(31) | YES | | NULL | |
| POSITIONINDEX | int(11) | YES | | NULL | |
+---------------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> show columns from taxableordering;
+------------------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+------------+------+-----+---------+-------+
| ID | bigint(20) | NO | PRI | | |
| OWNING | blob | YES | | NULL | |
| NONOWNING | blob | YES | | NULL | |
| TAXTYPEDETAIL_ID | bigint(20) | YES | MUL | NULL | |
| TAXABLE_ID | bigint(20) | YES | MUL | NULL | |
+------------------+------------+------+-----+---------+-------+
5 rows in set (0.01 sec)
Note the two blob fields, OWNING and NONOWNING, corresponding to methods marked with @Transient at all levels of the inheritance hierarchy.
I have tried varying combinations of placing @Transient on the abstract and concrete classes, with no luck...
Is my use of generics the source of the problem? My assumption was that annotating with @Transient would cause the persistence provider to completely ignore the methods.
With the exception of the blob fields, the above code performs the desired function. This was an experiment to maintain/persist the order of arbitrary List-based Entity relationships (since JPA spec doesn't have the indexcolumn that Hibernate does).
Any thoughts would be much appreciated. My next step is to move all annotations from properties and place them on the fields instead.
Thanks in advance.
[Message sent by forum member 'bhar99328' (bhar99328)]
http://forums.java.net/jive/thread.jspa?messageID=202539