1 2 Previous Next 22 Replies Latest reply: Apr 14, 2012 11:13 AM by xzeus Go to original post RSS
  • 15. Re: Discrimator values in versioned entities causing problems
    xzeus Newbie

    Hello Adam,

     

    i think i've got a similar problem here: I created a class "Range" with subclass "RangeAggregate", InheritanceType is SingleTable.

    The base class references another (abstract) class CriterionTarget (@OneToMany):

     

    Range                    CriterionTargetAbstract

    @OneToMany <---> @ManyToOne

     

    I can create new instances of CriterionTarget that reference RangeAggregate (child class of Range), persist the new CriterionTarget and the Audit-Table for Range-Table is filled correctly.

    But when i delete a CriterionTarget (or just the reference to Range) that references a RangeAggregate (child class of Range) the Audit-Table for Range-Table always is filled with wrong value in @DiscriminatorColumn:

     

    The DiscriminatorColumn is always filled with the value of the parent class Range - but only on when deleting the reference between the two objects.

    This can be an update with null value for Range reference in CriterionTargetAbstract or a delete of CriterionTargetAbstract that still has a reference.

     

    Update: I tried to remove CustomRevisionEntity - no change. The only possible workaround i figured out is to set @NotAudited on both sides, but that's of course not what i want...

     

    Id did some debugging - but the initial configration (discriminator value in MetadataTools.createSubclassEntity) seems to be correct.

    Maybe someone can give me a hint where i have to look for reading of discriminator value when deleting a reference?

     

     

    Do you have any idea what could lead to this behaviour? Maybe it's because of my CustomRevisionEntity (i pasted the code here)?

     

     

    Thanks.

     

    Thomas

    ---------------------

     

    @Audited

    @Entity

    @Inheritance(strategy = InheritanceType.SINGLE_TABLE)

    @DiscriminatorColumn(name = "BEREICH_TYP", discriminatorType = DiscriminatorType.CHAR, length = 1)

    @DiscriminatorValue(Range.DISCRIMINATOR_AGGREGATE)

    @Table( schema = Config.DATABASE_SCHEMA,

            name = Config.TABLE_PREFIX + "BEREICH" + Config.TABLE_POSTFIX,

            uniqueConstraints = @UniqueConstraint(columnNames =  { "BEREICH", "STATUS", "BEREICH_TYP" }))

    public class Range extends PersistentObject implements Serializable {


    public static final String DISCRIMINATOR_AGGREGATE = "A";

    public static final String DISCRIMINATOR_AWARD = "P";

    ...


    @OneToMany(mappedBy = "range")

    public Set<CriterionTargetAbstract> getCriterionTarget() {


    return criterionTarget;

    }

     

    @Audited

    @Entity

    @Inheritance(strategy = InheritanceType.SINGLE_TABLE)

    @DiscriminatorValue(Range.DISCRIMINATOR_AWARD) // Prämie

    public class RangeAward extends Range {

     

        private static final long serialVersionUID = 4953674778122811565L;

     

        private Range parentRange = null;   

     

        @ManyToOne(optional = true)

        @JoinColumn(name = "UEBERGEORDNETER_BEREICH")

        public Range getParentRange() {

            return parentRange;

        }

     

        public void setParentRange(Range parentRange) {

            this.parentRange = parentRange;

        }       

     

    }

     

    @Audited

    @Entity

    @Inheritance(strategy = InheritanceType.SINGLE_TABLE)

    @DiscriminatorColumn(name = "TYP", discriminatorType = DiscriminatorType.STRING, length = 6)

    @Table(    schema = Config.DATABASE_SCHEMA, name = Config.TABLE_PREFIX + "KRITERIUM_ZIEL" + Config.TABLE_POSTFIX,

            uniqueConstraints = @UniqueConstraint(columnNames =  { "KRIT_ID", "BEREICH_ID", "AGGREGAT_ID" }))

    public abstract class CriterionTargetAbstract extends PersistentObject implements Serializable, Comparable<CriterionTargetAbstract> {

    ...


    @ManyToOne(fetch = FetchType.LAZY)

    @JoinColumn(name = "BEREICH_ID")

    public Range getRange() {


    return range;

    }

     

    @Entity

    @Table(schema = Config.DATABASE_SCHEMA, name="REVINFO")

    @RevisionEntity(ExtendedRevisionListener.class)

    public class CustomRevisionEntity implements Serializable {

     

        private static final long serialVersionUID = -6138080818932576708L;

     

        private String userId = null;

     

        private int id;

     

        private long timestamp;

     

        private Set<String> modifiedEntityNames = new HashSet<String>();   

     

        @Id

        @GeneratedValue

        @RevisionNumber

        @Column(name = "REV")

        public int getId() {

            return id;

        }

     

        public void setId(int id) {

            this.id = id;

        }

     

        @Transient

        public Date getRevisionDate() {

            return new Date(timestamp);

        }

     

        @RevisionTimestamp

        @Column(name = "REVTSTMP")   

        public long getTimestamp() {

            return timestamp;

        }

     

        public void setTimestamp(long timestamp) {

            this.timestamp = timestamp;

        }

     

        @ElementCollection(fetch = FetchType.EAGER)

        @JoinTable(name = "REVCHANGES", joinColumns = @JoinColumn(name = "REV"))

        @Column(name = "ENTITYNAME")

        @Fetch(FetchMode.JOIN)

        @ModifiedEntityNames   

        public Set<String> getModifiedEntityNames() {

            return modifiedEntityNames;

        }

     

        public void setModifiedEntityNames(Set<String> modifiedEntityNames) {

            this.modifiedEntityNames = modifiedEntityNames;

        }

     

        public boolean equals(Object o) {

            if (this == o) return true;

            if (!(o instanceof CustomRevisionEntity)) return false;

            if (!super.equals(o)) return false;

     

            CustomRevisionEntity that = (CustomRevisionEntity) o;

     

            if (modifiedEntityNames != null ? !modifiedEntityNames.equals(that.modifiedEntityNames)

                                            : that.modifiedEntityNames != null) return false;

     

            return true;

        }

     

        public int hashCode() {

            int result = super.hashCode();

            result = 31 * result + (modifiedEntityNames != null ? modifiedEntityNames.hashCode() : 0);

            return result;

        }

     

        public String toString() {

            return "DefaultTrackingModifiedEntitiesRevisionEntity(" + super.toString() + ", modifiedEntityNames = " + modifiedEntityNames + ")";

        }   

     

        @Column(name = "USER_ID")

        public String getUserId() {

            return userId;

        }

     

        public void setUserId(String userId) {

            this.userId = userId;

        }   

     

    }

     

    Hibernate 4.1.1.Final


    <persistence-unit name="persistencePROD" transaction-type="JTA">

    <provider>org.hibernate.ejb.HibernatePersistence</provider>

    <jta-data-source>jdbc/pool/my_pool</jta-data-source>

    <exclude-unlisted-classes>false</exclude-unlisted-classes>

    <properties>

    <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.WeblogicTransactionManagerLookup"/>

    <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />

     


    <property name="hibernate.default_schema" value="MY_SCHEMA" />

    <property name="org.hibernate.envers.audit_strategy" value="org.hibernate.envers.strategy.ValidityAuditStrategy" />

    <property name="org.hibernate.envers.audit_strategy_validity_end_rev_field_name" value="REVEND" />

    <property name="org.hibernate.envers.audit_strategy_validity_store_revend_timestamp" value="true"/>

    <property name="org.hibernate.envers.audit_strategy_validity_revend_timestamp_fie ld_name" value="REVEND_TSTMP"/> 

    <property name="org.hibernate.envers.track_entities_changed_in_revision" value="true"/>

    <property name="org.hibernate.envers.audit_table_suffix" value="_AUD" />

    <property name="org.hibernate.envers.revision_field_name" value="REV" />

    <property name="org.hibernate.envers.revision_type_field_name" value="REVTYPE" />

    <property name="org.hibernate.envers.store_data_at_delete" value="true"/>  

    </properties> 

    </persistence-unit>

     

    Message was edited by: Thomas Schmid

  • 16. Re: Discrimator values in versioned entities causing problems
    Adam Warski Master

    Hmm weird ... can you provide an Envers test case (as simple as possible), demonstrating the problem? It will be much easier then.


    Adam

  • 17. Re: Discrimator values in versioned entities causing problems
    xzeus Newbie

    Hi Adam,

     

    thanks for your reply. I'm @holiday for one week now and can't access the project.

    Do you have a link to a tutorial about how to write a test case?

     

    Greetings

     

    Thomas

  • 18. Re: Discrimator values in versioned entities causing problems
    Adam Warski Master

    There's no tutorial, but I think just looking at one of the existing test cases will be pretty self-explanatory

     

    Adam

  • 19. Re: Discrimator values in versioned entities causing problems
    xzeus Newbie

    Hi Adam,

     

    it took some hours but finally i could reproduce the error in a test case

    I put the test case under org.hibernate.envers.test.integration.inheritance.single since i think the behaviour is affected by the @DiscriminatorColumn annotaion.

     

    TestCase is in ReferenceCreation.java

     

    Maybe you can have a look and tell me what's wrong. Thanks in advance.

     

    Greetings

    Thomas

  • 20. Re: Discrimator values in versioned entities causing problems
    Adam Warski Master

    Great! Can you create a bug in JIRA and attach it there? Either me or Łukasz will take a look

     

    Adam

  • 21. Re: Discrimator values in versioned entities causing problems
    xzeus Newbie

    Hi Adam,

     

    created JIRA Ticket: https://hibernate.onjira.com/browse/HHH-7249

     

    Greetings

     

    Thomas

     

    Nachricht geändert durch Thomas Schmid

  • 22. Re: Discrimator values in versioned entities causing problems
    xzeus Newbie

    Thx for the hint. I corrected the link above :-)

     

    Greetings

     

    Thomas

1 2 Previous Next