-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a reproducer for spring-projects/spring-framework#31050
The related error happen with Hibernate 6.2 with custom find methods on non-transactional use cases. See gh-188
- Loading branch information
1 parent
ed4fe18
commit 56263e7
Showing
6 changed files
with
150 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
data/data-jpa/src/main/java/com/example/data/jpa/NonTransactionalRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.example.data.jpa; | ||
|
||
import java.util.List; | ||
|
||
import com.example.data.jpa.model.Voucher; | ||
|
||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class NonTransactionalRunner implements CommandLineRunner { | ||
|
||
private final VoucherRepository voucherRepository; | ||
|
||
public NonTransactionalRunner(VoucherRepository voucherRepository) { | ||
this.voucherRepository = voucherRepository; | ||
} | ||
|
||
@Override | ||
public void run(String... args) { | ||
insertVouchers(); | ||
listVouchers(); | ||
} | ||
|
||
private void insertVouchers() { | ||
this.voucherRepository.save(new Voucher("0810000000", 0)); | ||
this.voucherRepository.save(new Voucher("0810000000", 1)); | ||
} | ||
|
||
private void listVouchers() { | ||
List<Voucher> vouchers = this.voucherRepository.findByMsisdn("0810000000"); | ||
vouchers.forEach(voucher -> System.out.printf("listVouchers(): voucher = %s%n", voucher)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
data/data-jpa/src/main/java/com/example/data/jpa/VoucherRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.example.data.jpa; | ||
|
||
import java.util.List; | ||
|
||
import com.example.data.jpa.model.Voucher; | ||
|
||
import org.springframework.data.repository.CrudRepository; | ||
|
||
public interface VoucherRepository extends CrudRepository<Voucher, Integer> { | ||
|
||
List<Voucher> findByMsisdn(String msisdn); | ||
|
||
} |
87 changes: 87 additions & 0 deletions
87
data/data-jpa/src/main/java/com/example/data/jpa/model/Voucher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.example.data.jpa.model; | ||
|
||
import java.util.Date; | ||
import java.util.Objects; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
|
||
@Entity | ||
public class Voucher { | ||
|
||
@Id | ||
@GeneratedValue | ||
private Integer id; | ||
|
||
private String msisdn; | ||
|
||
private int status; | ||
|
||
private Date dateCreated; | ||
|
||
protected Voucher() { | ||
} | ||
|
||
public Voucher(String msisdn, int status) { | ||
this.id = null; | ||
this.msisdn = msisdn; | ||
this.status = status; | ||
this.dateCreated = new Date(); | ||
} | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Integer id) { | ||
this.id = id; | ||
} | ||
|
||
public String getMsisdn() { | ||
return msisdn; | ||
} | ||
|
||
public void setMsisdn(String msisdn) { | ||
this.msisdn = msisdn; | ||
} | ||
|
||
public int getStatus() { | ||
return status; | ||
} | ||
|
||
public void setStatus(int status) { | ||
this.status = status; | ||
} | ||
|
||
public Date getDateCreated() { | ||
return dateCreated; | ||
} | ||
|
||
public void setDateCreated(Date dateCreated) { | ||
this.dateCreated = dateCreated; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
Voucher voucher = (Voucher) o; | ||
return status == voucher.status && Objects.equals(id, voucher.id) && Objects.equals(msisdn, voucher.msisdn) | ||
&& Objects.equals(dateCreated, voucher.dateCreated); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, msisdn, status, dateCreated); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Voucher{" + "id=" + id + ", msisdn='" + msisdn + '\'' + ", status=" + status + ", dateCreated=" | ||
+ dateCreated + '}'; | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.