I have migrated from Hibernate 4.2.2 to 5.1.2 and now I have a problem storing superclass with @Inheritance(strategy = InheritanceType.JOINED). My Promotion entity is:
@Entity
@Table(name = "promotion")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "promotion_type", discriminatorType = DiscriminatorType.STRING)
@XmlRootElement
public class Promotion implements Serializable {…
…
…
@Basic(optional = false)
@Column(name = "promotion_type", nullable = false, length = 17)
protected String promotionType;
…
…
}
One of the extended classes is PromotionEvent:
@Entity
@Table(name = "promotion_event")
@PrimaryKeyJoinColumn(name = "promotion_id")
@DiscriminatorValue("event")
@XmlRootElement
public class PromotionEvent extends Promotion {
…
…
}
In Hibernate 4.2.2 all was working, but now with Hibernate 5.1.2 when a promotion is stored I get the following exception: *ERROR pool-2-thread-2 SqlExceptionHelper.logExceptions - Parameter index out of range (16 > number of parameters, which is 15). * With the insert: insert into promotion (amount, client_id, description, end_datetime, event_end_datetime, event_start_datetime, hide_amount_at_ticket, name, percentage, promotion_type, requires_pda_alert, short_name, show_amount_original_at_ticket, start_datetime, state, status) values (?, ?, ?, ?, ?, ?, ?, ?, ?, 'event', ?, ?, ?, ?, ?, ?) So, seems that is trying to insert de @DisciminatorValue of PromotionEvent in the assigned @DiscriminatorColumn, but @DisicriminatorColumn is @Basic and then persisted. So, here is the problem. But, why in Hibernate 4.x this was not happening?, Is it a 4.x or 5.1.2 version bug?. I can see that it works if I make
@Basic(optional = false)
@Column(name = "promotion_type", nullable = false, insertable=false, length = 17)
protected String promotionType;
That’s to say, insertable=false, then it works and @DiscriminatorValue is inserted in promotion_type. Moreover, if I remove @DiscriminatorColumn from Promotion, it seems that all is working, but in this case I do not know how Hibernate knows the class type (with JOINED strategy I guess).
- Should it be recommended to put insertable=false?.
- Should it be better remove @DiscriminatorColumn if all it’s working?.
- Can not be @DiscriminatorColumn a @Basic and insertable attribute?, so why in H4.2.2 there was no problem?
|