I am a newbie here.
I have trying to convert old hibernate to JPA Annotation.
the issue is When i tried to do DiscriminatorValue for a model, it wont show up in the database table.
Here is the model
@Entity
@DiscriminatorValue("CurrencyType")
public class CurrencyTypeComposite extends ContractComponent {
/**
* serialVersionUID.
*/
private static final long serialVersionUID = 1L;
/**
* currencyType.
*/
private
String currencyType;
/**
* Full Constructor.
*/
public CurrencyTypeComposite(String currencyType, List<ContractComponent> list) {
this.currencyType = currencyType;
this.setChildList(list);
}
/**
* Default constructor .
*/
public CurrencyTypeComposite() {
}
/**
* The currency type linked to the contract composite.
*/
@Column(name = "currency_type", length = 250, nullable = true, columnDefinition = "VARCHAR(250)")
public String getCurrencyType() {
return currencyType;
}
/**
* Sets the currencyType as String.
*/
public void setCurrencyType(String currencyType) {
this.currencyType = currencyType;
}
/**
* Method to add a new contract composite.
*/
@Transient
public void add(ContractComponent child) {
this.getChildList().add(child);
}
/**
* Method to add a collection of children.
*/
@Transient
public void addAll(ArrayList<ContractComponent> children) {
this.getChildList().addAll(children);
}
/**
* Gets the id of the Composite object id.
*/
@Transient
public Long getObjectId() {
return new Long(0);
}
/**
* Gets the name of the Composite object.
*/
@Transient
public String getObjectName() {
return this.currencyType;
}
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CurrencyTypeComposite)) return false;
CurrencyTypeComposite that = (CurrencyTypeComposite) o;
if (!currencyType.equals(that.currencyType)) return false;
return true;
}
public int hashCode() {
return currencyType.hashCode();
}
public String toString() {
return "CurrencyTypeComposite{" +
"currencyType='" + currencyType + '\'' +
'}';
}
}
and another model
@Entity
@Table(name="contract_composite")
@Inheritance(strategy= InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="discriminator", discriminatorType = DiscriminatorType.STRING,length = 20)
public abstract class ContractComponent {
............
.
................
.
.
.........
}
The database shown is
mysql> desc contract_composite;
+--------------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+-------------+------+-----+---------+----------------+
| discriminator | varchar(20) | NO | | | |
| id | bigint(20) | NO | PRI | NULL | auto_increment |
| is_leaf | tinyint(1) | NO | | | |
| week_definition_id | bigint(20) | YES | MUL | NULL | |
| parent_id | bigint(20) | YES | MUL | NULL | |
| room_type_id | bigint(20) | NO | MUL | | |
| season_id | bigint(20) | NO | MUL | | |
| plan_id | bigint(20) | NO | MUL | | |
| hotel_id | bigint(20) | NO | MUL | | |
| rate_id | bigint(20) | NO | MUL | | |
+--------------------+-------------+------+-----+---------+----------------+
10 rows in set (0.00 sec)
Which isnt correct....
The correct database should be given below......
mysql> desc contract_composite;
+--------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+--------------+------+-----+---------+----------------+
| id | bigint(20) | NO | PRI | NULL | auto_increment |
| discriminator | varchar(255) | NO | | | |
| is_leaf | char(1) | YES | | NULL | |
| parent_id | bigint(20) | YES | MUL | NULL | |
| plan_id | bigint(20) | YES | MUL | NULL | |
| room_type_id | bigint(20) | YES | MUL | NULL | |
| currency_type | varchar(250) | YES | | NULL | (* ** This is missing ) |
| hotel_id | bigint(20) | YES | MUL | NULL | |
| rate_id | bigint(20) | YES | MUL | NULL | |
| season_id | bigint(20) | YES | MUL | NULL | |
| week_definition_id | bigint(20) | YES | MUL | NULL | |
+--------------------+--------------+------+-----+---------+----------------+
11 rows in set (0.00 sec)
Hope you understood what i mean..... Thanks
alot in advance....