While working with Java Persistence using ORM Layer, new feature from Oralce 11g can be useful.
E.g. Virtual Column.
Whenever want to use Virtual Column in JPA Entity, it should follow:
E.g. Virtual Column.
Whenever want to use Virtual Column in JPA Entity, it should follow:
- Field should not be Updatable.
- Field should not be populated while creating the entity.
For such scenario, one has to use below annotation on field:
Below is Detailed Example JPA Entity with Virtual Column usage:
Virtual Column Should be added like:
alter table cosnumers add(
IS_ADMIN GENERATED ALWAYS AS ( CASE WHEN CONSUMER_ID IS NOT NULL THEN 1 ELSE 0 END)
);
|
JPA Entity Should define field for Virtual Column as shown below:
Package com.acp.jpa;
import javax.persistence.Column;
import javax.persistence.Entity;
@Entity
public class Consumer {
private Long consumerID;
@Column(insertable=false, updatable=false)
private boolean isAdmin;
/**
* @return the consumerID
*/
public Long getConsumerID() {
return consumerID;
}
/**
* @param consumerID the consumerID to set
*/
public void setConsumerID(Long consumerID) {
this.consumerID = consumerID;
}
//--- For Virtual Column - Provide only Getters.
/**
* @return the isAdmin
*/
public boolean isAdmin() {
return isAdmin;
}
}
|
--
III Cheers!