Open roma2341 opened 11 months ago
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();
}
}
Here is retreived object
MultisetTupleTransformer received "1"
I think that problem is here: BooleanBasicUserType.fromString("1") returns false
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.
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
.
@Mapping(fetch = FetchStrategy.MULTISET) breaks boolean fields mapping.
Description
My DripTriggerEntityView class boolean fields are always false If I use @Mapping(fetch = FetchStrategy.MULTISET). If I use @Mapping(fetch = FetchStrategy.JOIN) everything is ok, boolean fields have correct values.
My views and method to fetch view:
It generates query:
This SQL produces Json for trigger:
as you can see both f4(enabled) and f7(retrospection_enabled) are true, but object contains only false...
Expected behavior
boolean fields have valid value
Actual behavior
boolean fields always false
Steps to reproduce
already provided
Environment
blaze-persistence 1.6.8 spring-boot-starter-parent 2.7.17 Windows 11 Database Mysql 8