-->
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.  [ 7 posts ] 
Author Message
 Post subject: Problems storing superclass.
PostPosted: Thu Nov 03, 2016 9:27 am 
Newbie

Joined: Wed Oct 19, 2016 2:57 am
Posts: 13
Hi all,
I have an entity PromotionEvent that extends Promotion:
@Entity
@Table(name = "promotion_event")
@PrimaryKeyJoinColumn(name = "promotion_id")
@DiscriminatorValue("event")
@XmlRootElement
public class PromotionEvent extends Promotion {

@Basic(optional = false)
@Column(name = "start_time", nullable = false)
@Temporal(TemporalType.TIME)
private Date startTime;
@Basic(optional = false)
@Column(name = "end_time", nullable = false)
@Temporal(TemporalType.TIME)
private Date endTime;
@Basic(optional = false)
@Column(name = "week_day", nullable = false, length = 11)
private String weekDay;


And when try to store PromotionEvent 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', ?, ?, ?, ?, ?, ?)

in my store method:
public void store(PromotionEvent promotionEvent) {

session.saveOrUpdate(promotionEvent);

}



Promtion has:
@Entity
@Table(name = "promotion")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "promotion_type", discriminatorType = DiscriminatorType.STRING)
@XmlRootElement
public class Promotion implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "promotion_id", nullable = false)
protected Integer promotionId;
....
.....
....


I using Hibernate 5.1.2
Best regards.


Top
 Profile  
 
 Post subject: Re: Problems storing superclass.
PostPosted: Thu Nov 03, 2016 9:56 am 
Newbie

Joined: Wed Oct 19, 2016 2:57 am
Posts: 13
It seems to work if in Promotion I remove @DiscriminatorColumn(name = "promotion_type", discriminatorType = DiscriminatorType.STRING)
But I do not know if this implies a disaster :-D


Top
 Profile  
 
 Post subject: Re: Problems storing superclass.
PostPosted: Thu Nov 03, 2016 12:08 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Looks like a bug. Can you send a replicating test case?


Top
 Profile  
 
 Post subject: Re: Problems storing superclass.
PostPosted: Fri Nov 04, 2016 5:41 am 
Newbie

Joined: Wed Oct 19, 2016 2:57 am
Posts: 13
Thank you Vlad.
Now is not easy to implement this test in our application.
By the moment I will keep removed the @DiscriminatorColumn. I've checked that Hibernate is able to discriminate the correct type. I gess that it's using JOINED strategy and for example a Promotion that is type PromotionEvent can be read as PromotionEvent.

All was working with Hibernate 4.2.2 but after a migration to 5.1.2 fails. So maybe in 4.2.2 @DiscriminatorColumn was "bypassed".


Top
 Profile  
 
 Post subject: Re: Problems storing superclass.
PostPosted: Fri Nov 04, 2016 6:17 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
I still think this is a bug since you said that it was working in 4.x and in 5.1, it fails. Please open a JIRA issue for it.


Top
 Profile  
 
 Post subject: Re: Problems storing superclass.
PostPosted: Fri Nov 04, 2016 7:43 am 
Newbie

Joined: Wed Oct 19, 2016 2:57 am
Posts: 13
Ok.
Moreover, I have seen that it tries to store the DiscriminatorValue in BBDD, but my DiscriminatorColumn is the same that an existent attribute (promotionType).
For this reason I think that in previous version Hibernate was not inserting DiscriminatorValue of child classes into the column that I assigned as DiscirminatorColumn, or with new version Hibernate can not store DiscriminatorValues on a DiscriminatorColumn that is an attribute too.

I've tried to create a new column promo_tp in my promo table and rename DiscriminatorColumn as @DiscriminatorColumn(name = "promo_tp", discriminatorType = DiscriminatorType.STRING) and the DiscriminatorValues of child classes are stored in this new column.

That's to say, now it's not possible to use an existent column (a property with setters and getters) as a DiscriminatorColumn.

Thank you again.


Top
 Profile  
 
 Post subject: Re: Problems storing superclass.
PostPosted: Sat Nov 05, 2016 1:47 pm 
Newbie

Joined: Wed Oct 19, 2016 2:57 am
Posts: 13
vlad wrote:
I still think this is a bug since you said that it was working in 4.x and in 5.1, it fails. Please open a JIRA issue for it.

Opened with more details on what is happening https://hibernate.atlassian.net/browse/ ... ?filter=-4

And http://stackoverflow.com/questions/4043 ... 3_40437158

Thanks.


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

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.