Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » EclipseLink enhancement request in bugzilla(An enhancement request is filled on bugzilla. Please give a look an eventually a support ... )
EclipseLink enhancement request in bugzilla [message #779964] Mon, 16 January 2012 22:49
Claude Bernard Diesse is currently offline Claude Bernard DiesseFriend
Messages: 9
Registered: December 2011
Junior Member
I have filled an enhancement request on EclipseLink in bugzilla system : Bug 367630.

Quote:
Enhancement: Identity Override for optional auto generator strategy in derived concrete entities


Please give a supporting vote to help it be in the next release wagons.
Here is the submitted description. (Also feel free to add comments or submit others equivalent solutions)

Quote:

The context here is how to align JPA capabilities to Java generics, and allow
to write clean java codes.

Considering JPA coding, I have some preferences :
- Field mapping over method mapping
- Try to use all power of java generics in java model design
- Factor and reduce code in generic mapped super classes (for maintenance and
safety reasons)
All those advantages are lost because of a missing JPA function : Identity
generation override capability

Lets show it in a simple reduced example

BaseEntity<K> : a generic mapped super class, with a prim key of type K.

LongBasedEntity : a concrete derived entity class mapped on "LONG_ENTITY" table
with "BIGINT" prim key type

StringBasedEntity : a concrete derived entity class mapped on "STRING_ENTITY"
table with "VARCHAR(32)" prim key type

SeqBasedEntity : a concrete derived entity class mapped on "SEQ_ENTITY" table
with "BIGINT" prim key type (But with auto generate sequence values in this
case "Sequence/Table/Auto generator" ...)

I want the abstract BaseEntity class to host all common fields and methods...
And I want specially to declare the id variable in that root class, but with
generic type.

For LongBasedEntity and StringBasedEntity, I can use @AttributeOverride and
@AssociationOveride to achieve the mapping to related tables.

But for SeqBasedEntity, there is actually no way to override the generation
strategy ... Because there is no
annotation for that.

So, I am proposing to add a new annotation :
@IdOverride(generate=GeneratedValue(...))

This make sense, because JPA already allow mapping override at the entity class
level :
- So, if you have defined the id in higher level classes, you can just
specify at the concrete entity class level, a new generation strategy, and give
it as the @IdOverride.generate parameter

An example follow:

@MappedSuperclass public abstract class BaseEntity<K extends Serializable>
implements Serializable
{
private static final long serialVersionUID = 1L;
@Version @Column(name = "VERSION") protected Integer version;
@Id @Basic(optional = false) @Column(name = "ID", nullable = false) protected
K id;

protected BaseEntity() { super(); }
protected BaseEntity(K xid) { this.id = xid; }
public K getId() { return id; }
public void setId(K xid) { this.id = xid; }
}

@Entity @Table(name = "LONG_ENTITY")
public abstract class LongBasedEntity extends BaseEntity<Long>
{
private static final long serialVersionUID = 1L;
@Basic(optional = false) @Column(name = "ENT_TYPE", length = 32) private
String entType;

protected LongBasedEntity() { super(); }
protected LongBasedEntity(Long id) { super(id); }

public String getEntityType() { return entType; }
public void setEntityType(String s) { this.entType = s; }

}

@Entity @Table(name = "STRING_ENTITY")
public abstract class StringBasedEntity extends ManagedEntity<String>
{
private static final long serialVersionUID = 1L;
@Basic(optional = false) @Column(name = "ENT_TYPE", length = 32) private
String entType;

protected StringBasedEntity() { super(); }
protected StringBasedEntity(String id) { super(id); }

public String getEntityType() { return entType; }
public void setEntityType(String s) { this.entType = s; }

}

@Entity @Table(name = "SEQ_ENTITY")
@TableGenerator(name="METAINFO_GEN", table="SEQUENCE_TABLE",
pkColumnName="SEQ_NAME", valueColumnName="SEQ_COUNT", pkColumnValue="METAINFO")
@IdOverride(generate=@GeneratedValue(strategy=GenerationType.TABLE,
generator="METAINFO_GEN"))
public abstract class SeqBasedEntity extends BaseEntity<Long>
{
private static final long serialVersionUID = 1L;
@Basic(optional = false) @Column(name = "ENT_TYPE", length = 32) private
String entType;

protected SeqBasedEntity() { super(); }
protected SeqBasedEntity(Long id) { super(id); }

public String getEntityType() { return entType; }
public void setEntityType(String s) { this.entType = s; }

}

By using @IdOverride, I can now separate the key generation strategy and the
inheritance and data type problems.

I also thought to use @AttributeOverride with an optional generate parameter...
But this will certainly add overhead in existing implementation error tracking.

There are many others valuable reasons to add this functionality ... But as
coding preferences are different from developers, I prefer to let others give
their thoughts for this request for enhancement.

Thanks for taking this problem very seriously because I have tone of codes
waiting for refactoring.

Regards.




Previous Topic:Error when trying to use PLSQLTable type as an IN parameter in a PLSQLStoredProcedure in eclipse lin
Next Topic:EclipseLink enhancement request in bugzilla
Goto Forum:
  


Current Time: Fri Apr 19 11:20:59 GMT 2024

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

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

Back to the top