[hibernate-issues] [Hibernate-JIRA] Created: (HHH-7214) DiscriminatorValue

Lorber Sebastien (JIRA) noreply at atlassian.com
Tue Apr 3 05:54:50 EDT 2012


DiscriminatorValue
------------------

                 Key: HHH-7214
                 URL: https://hibernate.onjira.com/browse/HHH-7214
             Project: Hibernate ORM
          Issue Type: Improvement
          Components: annotations
    Affects Versions: 3.6.4
         Environment: Oracle + Hibernate 3.6.4 final + Java 1.6
            Reporter: Lorber Sebastien


I have an abstract entity with the following annotations:

@Entity
@Table(name = LineBlock.TABLE_NAME)
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "blockType", discriminatorType = DiscriminatorType.STRING)
public abstract class LineBlock implements Serializable, Visitable {




I have 2 sub entities:

@Entity
@DiscriminatorValue("EMAIL")
public class EmailBlock extends LineBlock {

@Entity
@DiscriminatorValue("EMAIL")
public class ArgusBlock extends LineBlock {



Actually it was a mistake i made to not change the discriminator value... But it took me some time to figure out the problem was so easy to solve...


The problem is that when i was saving an object refering an ArgusBlock entity, when loading that object, it seems Hibernate took the first block it found with that discriminator value, which in this case was the EmailBlock.


I think when a discriminator value is used twice or more, an exception should prevent this "random" behavior".




The problem seems to be there:
org.hibernate.persister.entity.SingleTableEntityPersister#getSubclassForDiscriminatorValue
There is a Map<Discriminator,EntityName> in which we probably try to put twice the same discriminator key, so one value override the other.



The problem seems easy to solve and i can try doing it myself. I see 2 possible solutions:
- Raise exception when we try to override a key in the map construction
- Use a multimap and raise exception when accessing the map with multiple values



Don't really know if it's a bug or improvement, but i think it's always better to be fail-fast in such cases


--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list