-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Strange generated id value for Inheritance (Table per class)
PostPosted: Wed Jun 09, 2010 9:16 am 
Newbie

Joined: Fri Jun 04, 2010 8:57 pm
Posts: 19
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.