Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Reusing a column across subclasses in eclipselink single table inheritance
Reusing a column across subclasses in eclipselink single table inheritance [message #1699275] Tue, 23 June 2015 08:18 Go to next message
MANISHA SHARMA is currently offline MANISHA SHARMAFriend
Messages: 1
Registered: September 2014
Junior Member
Hi,



In a simple inheritance tree, there are only two subclass entities.



The subclasses both store a key-value pair, but one will be holding a type Encrypted String, and the other one a plain old String.



Now, my question is can I do this:


@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract Attribute {
   @Id
   private Integer id;

   @Column(name="attribute_key")
   private String key;
}

@Entity
public EncryptedAttribute extends Attribute {
   @Column(name="attribute_value")
   private EncryptedString encryptedValue;
}

@Entity
public UnEncryptedAttribute extends Attribute {
   @Column(name="attribute_value")
   private String plainValue;  
}


The Encrypted String and plain String should both end up as varchars in the db, but can I store persistent attributes associated with different sub-classes in the same column? This would avoid the side-effect of storing null values in columns which aren't used in a particular row.
Re: Reusing a column across subclasses in eclipselink single table inheritance [message #1699498 is a reply to message #1699275] Wed, 24 June 2015 15:14 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
This should work as long as the mapping would use the same database field type. Also remember that you may have difficulty querying on the field - this shouldn't be a problem for EclipseLink generated queries, as it will filter on the type, but might if you are using native queries.
Previous Topic:Using XMLType in Oracle XE-Database with Eclipselink
Next Topic:@OneToMany does not work with schema-generation = drop-and-create
Goto Forum:
  


Current Time: Thu Apr 25 07:35:56 GMT 2024

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

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

Back to the top