Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import com.querydsl.sql.RelationalPath;
import com.querydsl.sql.RelationalPathBase;
import org.springframework.core.ResolvableType;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.mapping.PreferredConstructor;
import org.springframework.data.mapping.model.PreferredConstructorDiscoverer;
import org.springframework.data.relational.core.mapping.Embedded;
import org.springframework.util.ReflectionUtils;

Expand Down Expand Up @@ -92,20 +93,13 @@ private Optional<Class<?>> getEmbeddedType(Class<?> type, Parameter parameter) {

@Nullable
private Constructor<?> getConstructor(Class<?> type) {
Constructor<?>[] declaredConstructors = type.getDeclaredConstructors();
Constructor<?> persistenceConstructor = Arrays.stream(declaredConstructors)
.filter(constructor -> constructor.isAnnotationPresent(
PersistenceConstructor.class))
.findAny()
.orElse(null);

if (Objects.nonNull(persistenceConstructor)) {
return persistenceConstructor;
PreferredConstructor<?, ?> preferredConstructor = PreferredConstructorDiscoverer.discover(type);

if (preferredConstructor == null) {
return null;
}

return Arrays.stream(declaredConstructors)
.max(Comparator.comparingInt(Constructor::getParameterCount))
.orElse(null);
return preferredConstructor.getConstructor();
}

public RelationalPathBase<?> getRelationalPathBaseFromQueryRepositoryClass(Class<?> repositoryInterface) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.*;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.PersistenceConstructor;

@Getter
@EqualsAndHashCode
Expand All @@ -22,6 +23,7 @@ public class NoArgsEntity {
this.value = null;
}

@PersistenceConstructor
public NoArgsEntity(Long id, String value) {
this.id = id;
this.value = value;
Expand Down