Hi,
I have just started learning JPA and Hibernate. I have come across a strange behavior. I am trying to map inheritance with the following details.
Abstract Class - Billing
Subclass 1 - BankAccountBilling extends Billing
Subclass 2 - CreditCardBilling extends Billing.
I am using annotations to get Table per concrete class (union) behavior. The Billing superclass has a generated id with strategy=GenerationType.TABLE (other strategies don't work in this case). When I create instances of subclasses and persist them, they seem to work nicely, incrementing the id with each insert.
However if I shut down the hibernate and then restart again, then after inserting the subclass instance, the id generated is 32769 (instead of the next available number). Why is the next available id not used?
I have one more doubt. We close the EntityManagerFactory when the user exits the application (assuming swing application). When the application is again started then we have to create EntityManagerFactory. Is the persistence code (i.e the code generated by hibernate for persistence) is created again or the classes are just loaded instead. In case the presistence code is generated afresh, then will it be a performance issue (in case of large number of entities) ?
Here is the code that I am using.
Code:
@Entity
@Inheritance (strategy=InheritanceType.TABLE_PER_CLASS)
public abstract class Billing {
@Id
@GeneratedValue (strategy=GenerationType.TABLE)
@Column(name="BillingId")
private Long id;
.......
}
@Entity
@Table(name="BankAccountBilling")
public class BankAccountBilling extends Billing{
..........
}
@Entity
@Table(name="CreditCardBilling")
public class CreditCardBilling extends Billing {
......
}
regards,
Nirvan.