gpt4 book ai didi

Querydsl @QueryInit 不工作

转载 作者:行者123 更新时间:2023-12-02 21:44:12 26 4
gpt4 key购买 nike

我正在开发一个最近接手的项目,并尝试转换为使用 Querydsl。

我有一个列表类:

@Entity
public class EListing {

...

private static final long serialVersionUID = 7729681308228522567L;

@QueryInit("provider")
private EExternalId masterId;

@OneToOne(fetch = FetchType.EAGER,
orphanRemoval = true,
cascade = CascadeType.ALL)
@JoinColumn(name = "master_ext_id")
@NotNull(message = EvalMessageCode.LISTING_MASTERID_NOTNULL)
@Valid
public EExternalId getMasterId() {

return masterId;
}

public void setMasterId(final EExternalId masterId) {

this.masterId = masterId;
}

...

}

以及外部 ID 类:

@Entity
public class EExternalId implements Serializable {

public static final String FIELD_PROVIDER_PREFIX = "provder.";

private static final long serialVersionUID = -4577890108032056848L;

private String externalId;

private Long id;

private EDataProvider provider;

@Column(name = "external_id",
updatable = false)
@NotBlank(message = EvalMessageCode.EXTID_ID_NOTBLANK)
public String getExternalId() {

return externalId;
}

@Id
@GeneratedValue(generator = "external_id_seq")
@Column(name = "id")
public Long getId() {

return id;
}

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "provider_id",
nullable = false,
updatable = false)
@IndexedEmbedded(prefix = FIELD_PROVIDER_PREFIX)
@NotNull(message = EvalMessageCode.EXTID_PROVIDER_NOTNULL)
public EDataProvider getProvider() {

return provider;
}

public void setExternalId(final String externalId) {

this.externalId = externalId;
}

public void setId(final Long id) {

this.id = id;
}

public void setProvider(final EDataProvider provider) {

this.provider = provider;
}

}

我有一个 ListingPredicates 类:

public class ListingPredicates {

public static BooleanExpression byMasterExternalIdAndProviderId(
final String externalId, final Long providerId) {

QEListing listing = QEListing.eListing;

return listing.masterId.externalId.equalsIgnoreCase(externalId).and(
listing.masterId.provider.id.eq(providerId));
}
}

当我尝试访问ListingPredicates.byMasterExternalIdAndProviderId()中的listing.masterId.provider时,provider为空,尽管我使用了QueryInit()

如果我调试 Querydsl“Q”类的创建,则 masterId 没有初始化路径。

有人可以解释一下为什么我的 @QueryInit 不起作用吗?

更新:

QE列表类:

/**
* QEListing is a Querydsl query type for EListing
*/
@Generated("com.mysema.query.codegen.EntitySerializer")
public class QEListing extends EntityPathBase<EListing> {

private static final long serialVersionUID = -1539977778;

private static final PathInits INITS = PathInits.DIRECT;

public static final QEListing eListing = new QEListing("eListing");

public final com.mycompany.core.model.account.QEAccount account;

public final StringPath address = createString("address");

public final StringPath address2 = createString("address2");

public final StringPath businessName = createString("businessName");

public final com.mycompany.core.model.location.QECity city;

public final SetPath<com.mycompany.core.model.listing.contact.EListingContact, com.mycompany.core.model.listing.contact.QEListingContact> contactInfo = this.<com.mycompany.core.model.listing.contact.EListingContact, com.mycompany.core.model.listing.contact.QEListingContact>createSet("contactInfo", com.mycompany.core.model.listing.contact.EListingContact.class, com.mycompany.core.model.listing.contact.QEListingContact.class, PathInits.DIRECT);

public final DateTimePath<java.util.Calendar> createdDate = createDateTime("createdDate", java.util.Calendar.class);

public final SetPath<com.mycompany.core.model.listing.contact.EEnhancedInfo, com.mycompany.core.model.listing.contact.QEEnhancedInfo> enhancedInfo = this.<com.mycompany.core.model.listing.contact.EEnhancedInfo, com.mycompany.core.model.listing.contact.QEEnhancedInfo>createSet("enhancedInfo", com.mycompany.core.model.listing.contact.EEnhancedInfo.class, com.mycompany.core.model.listing.contact.QEEnhancedInfo.class, PathInits.DIRECT);

public final SetPath<EExternalId, QEExternalId> externalIds = this.<EExternalId, QEExternalId>createSet("externalIds", EExternalId.class, QEExternalId.class, PathInits.DIRECT);

public final SetPath<com.mycompany.core.model.heading.EHeading, com.mycompany.core.model.heading.QEHeading> headings = this.<com.mycompany.core.model.heading.EHeading, com.mycompany.core.model.heading.QEHeading>createSet("headings", com.mycompany.core.model.heading.EHeading.class, com.mycompany.core.model.heading.QEHeading.class, PathInits.DIRECT);

public final SetPath<EHoursOfOperation, QEHoursOfOperation> hoursOfOperations = this.<EHoursOfOperation, QEHoursOfOperation>createSet("hoursOfOperations", EHoursOfOperation.class, QEHoursOfOperation.class, PathInits.DIRECT);

public final NumberPath<Long> id = createNumber("id", Long.class);

public final NumberPath<java.math.BigDecimal> latitude = createNumber("latitude", java.math.BigDecimal.class);

public final NumberPath<java.math.BigDecimal> longitude = createNumber("longitude", java.math.BigDecimal.class);

public final QEExternalId masterId;

public final DateTimePath<java.util.Calendar> modifiedDate = createDateTime("modifiedDate", java.util.Calendar.class);

public final SetPath<EDataProvider, QEDataProvider> removeForProviders = this.<EDataProvider, QEDataProvider>createSet("removeForProviders", EDataProvider.class, QEDataProvider.class, PathInits.DIRECT);

public final SetPath<ESponsorship, QESponsorship> sponsorships = this.<ESponsorship, QESponsorship>createSet("sponsorships", ESponsorship.class, QESponsorship.class, PathInits.DIRECT);

public final com.mycompany.core.model.location.QEState state;

public final StringPath vanityName = createString("vanityName");

public final com.mycompany.core.model.location.QEZipCode zipCode;

public final StringPath zipCodeExt = createString("zipCodeExt");

public QEListing(String variable) {
this(EListing.class, forVariable(variable), INITS);
}

@SuppressWarnings("all")
public QEListing(Path<? extends EListing> path) {
this((Class)path.getType(), path.getMetadata(), path.getMetadata().isRoot() ? INITS : PathInits.DEFAULT);
}

public QEListing(PathMetadata<?> metadata) {
this(metadata, metadata.isRoot() ? INITS : PathInits.DEFAULT);
}

public QEListing(PathMetadata<?> metadata, PathInits inits) {
this(EListing.class, metadata, inits);
}

public QEListing(Class<? extends EListing> type, PathMetadata<?> metadata, PathInits inits) {
super(type, metadata, inits);
this.account = inits.isInitialized("account") ? new com.mycompany.core.model.account.QEAccount(forProperty("account"), inits.get("account")) : null;
this.city = inits.isInitialized("city") ? new com.mycompany.core.model.location.QECity(forProperty("city"), inits.get("city")) : null;
this.masterId = inits.isInitialized("masterId") ? new QEExternalId(forProperty("masterId"), inits.get("masterId")) : null;
this.state = inits.isInitialized("state") ? new com.mycompany.core.model.location.QEState(forProperty("state")) : null;
this.zipCode = inits.isInitialized("zipCode") ? new com.mycompany.core.model.location.QEZipCode(forProperty("zipCode"), inits.get("zipCode")) : null;
}

}

maven apt 插件的 Pom 配置:

<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>maven-apt-plugin</artifactId>
<version>1.0.4</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources</outputDirectory>
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
<!-- <logOnlyOnError>true</logOnlyOnError> -->
</configuration>
</execution>
</executions>
</plugin>

最佳答案

Querydsl JPA 注释处理器根据相关注释的使用位置,在类的基础上决定在检查中是否考虑字段、访问器或两者。此阶段仅考虑 JPA 注释。

由于您的 JPA 注释是在 getter 中定义的,因此 QueryInit 注释也需要放在那里。

关于Querydsl @QueryInit 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16824037/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com