Coder Social home page Coder Social logo

Comments (6)

beikov avatar beikov commented on July 18, 2024 1

Hey there. The fix should be pretty simple, so if you want to take a stab at trying to provide a PR for this, I'd be very grateful. In the meantime, you should be able to register a custom BooleanBasicUserType with a custom conversion strategy via com.blazebit.persistence.view.spi.EntityViewConfiguration#registerBasicUserType.

from blaze-persistence.

roma2341 avatar roma2341 commented on July 18, 2024

DripCampaignEntity:

@Table(name = "drip_campaign")
@Entity(name = "DripCampaign" )
@Audited
@Getter
@Setter
@Builder(toBuilder = true)
@AllArgsConstructor
@NoArgsConstructor
@Where(clause="deleted_at is null")
@NamedEntityGraph(name = DripCampaignEntity.DRIP_CAMPAIGN_ENTITY_GRAPH_ALL,
        attributeNodes = {
                @NamedAttributeNode(value = "steps", subgraph = "steps.template"),
                @NamedAttributeNode(value = "campaignSubscriptionTriggers"),
        },subgraphs = {
        @NamedSubgraph(name = "steps.template",
                attributeNodes =
                        {@NamedAttributeNode("template")})
        })
public class DripCampaignEntity extends AbstractAuditingResource<Long> {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Long id;

    @Size(max = 1024)
    private String name;

    private Instant preferredSendDate;
    private Instant preferredSendTime;

    @Column(nullable = false, columnDefinition = "boolean default false")
    @Builder.Default
    private boolean enabled = false;

    @Column(updatable = false,insertable = false)
    private Instant lastSentAt;

    @Column(name="steps_count", nullable = false,  columnDefinition = "int default 0")
    private int stepsCount = 0;

    @OneToMany(mappedBy = "dripCampaign", fetch = FetchType.LAZY)
    @Where(clause="deleted_at is null")
    @OrderBy("stepIndex")
    @Builder.Default
    @Fetch(FetchMode.SUBSELECT)
    private List<DripCampaignStepEntity> steps = new ArrayList<>();


    @NotAudited
    @OneToMany(fetch = FetchType.LAZY,mappedBy = "dripCampaign",orphanRemoval = true,cascade={CascadeType.REMOVE})
    private Set<DripTriggerEntity> campaignSubscriptionTriggers = new HashSet<>();

    /*Don't use directly*/
    @NotAudited
    @OneToMany(mappedBy = "dripCampaign", fetch = FetchType.LAZY)
    @Builder.Default
    private Set<DripCampaignSubscriberEntity> subscribedUsers = new HashSet<>();

    @Column(updatable = false)
    private Instant deletedAt;


    public final static String DRIP_CAMPAIGN_ENTITY_GRAPH_ALL = "drip_campaign.all";

    @Override
    public final boolean equals(Object o) {
        if (this == o) return true;
        if (o == null) return false;
        Class<?> oEffectiveClass = o instanceof HibernateProxy ? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass() : o.getClass();
        Class<?> thisEffectiveClass = this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass() : this.getClass();
        if (thisEffectiveClass != oEffectiveClass) return false;
        DripCampaignEntity that = (DripCampaignEntity) o;
        return getId() != null && Objects.equals(getId(), that.getId());
    }

    @Override
    public final int hashCode() {
        return this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode() : getClass().hashCode();
    }
}

DripTriggerEntity:

@Table(name = "drip_trigger")
@Entity(name="DripTrigger")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "type",discriminatorType=DiscriminatorType.STRING)
@Getter
@Setter
public abstract class DripTriggerEntity extends AbstractAuditingResource<Long> {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    protected Long id;
    /*
    * The variable determines whether the logic should be triggered for existing data (true)
    * or only for new ones (false).
    */
    @Column(nullable = false, columnDefinition = "boolean default false")
    protected boolean retrospectionEnabled = false;

    @Builder.Default
    @Column(nullable = false, columnDefinition = "boolean default false")
    protected boolean enabled = false;

    @Enumerated(EnumType.STRING)
    @Getter(AccessLevel.NONE)
    @Column(name="type", insertable = false, updatable = false)
    protected DripTriggerType type;

    @ManyToOne(fetch = FetchType.LAZY,optional = false)
    @JoinColumn(name = "drip_campaign", updatable = false)
    protected DripCampaignEntity dripCampaign;

    @Transient
    public DripTriggerType getTriggerType() {
        var discriminatorAnnotation = this.getClass().getAnnotation(DiscriminatorValue.class);
         if(discriminatorAnnotation == null) {
             throw new PublicCrmRuntimeException("Cannot get discriminator value of Base Entity class");
         }
         return DripTriggerType.valueOf(discriminatorAnnotation.value());
    }

    @Override
    public final boolean equals(Object o) {
        if (this == o) return true;
        if (o == null) return false;
        Class<?> oEffectiveClass = o instanceof HibernateProxy ? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass() : o.getClass();
        Class<?> thisEffectiveClass = this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass() : this.getClass();
        if (thisEffectiveClass != oEffectiveClass) return false;
        DripTriggerEntity that = (DripTriggerEntity) o;
        return getId() != null && Objects.equals(getId(), that.getId());
    }

    @Override
    public final int hashCode() {
        return this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode() : getClass().hashCode();
    }
}

from blaze-persistence.

roma2341 avatar roma2341 commented on July 18, 2024

image
Here is retreived object

from blaze-persistence.

roma2341 avatar roma2341 commented on July 18, 2024

image
MultisetTupleTransformer received "1"

from blaze-persistence.

roma2341 avatar roma2341 commented on July 18, 2024

I think that problem is here:
image
BooleanBasicUserType.fromString("1") returns false

from blaze-persistence.

roma2341 avatar roma2341 commented on July 18, 2024

As i understand converter now supports only "true", "false" values, and doesn't support 1 or 0, but it takes 1 or 0 if we use multiset.

from blaze-persistence.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.