forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(panache): repository operations failure with multiple persistence…
… units in 1.8.0.cr1 Fixes quarkusio#11842
- Loading branch information
Showing
7 changed files
with
147 additions
and
11 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
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
37 changes: 37 additions & 0 deletions
37
...uarkus/hibernate/orm/panache/deployment/test/multiple_pu/repository/Issue11842Entity.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,37 @@ | ||
package io.quarkus.hibernate.orm.panache.deployment.test.multiple_pu.repository; | ||
|
||
import java.io.Serializable; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
|
||
@Entity | ||
public class Issue11842Entity implements Serializable { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Integer id; | ||
|
||
@Column(length = 64) | ||
private String name; | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Integer id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
...us/hibernate/orm/panache/deployment/test/multiple_pu/repository/Issue11842Repository.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,9 @@ | ||
package io.quarkus.hibernate.orm.panache.deployment.test.multiple_pu.repository; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
import io.quarkus.hibernate.orm.panache.PanacheRepositoryBase; | ||
|
||
@ApplicationScoped | ||
public class Issue11842Repository implements PanacheRepositoryBase<Issue11842Entity, Integer> { | ||
} |
24 changes: 24 additions & 0 deletions
24
...rkus/hibernate/orm/panache/deployment/test/multiple_pu/repository/Issue11842Resource.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,24 @@ | ||
package io.quarkus.hibernate.orm.panache.deployment.test.multiple_pu.repository; | ||
|
||
import javax.inject.Inject; | ||
import javax.transaction.Transactional; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
import org.jboss.resteasy.annotations.jaxrs.PathParam; | ||
|
||
@Path("/repository") | ||
public class Issue11842Resource { | ||
@Inject | ||
Issue11842Repository repository; | ||
|
||
@GET | ||
@Path("/{name}") | ||
@Transactional | ||
public String addAndReturnName(@PathParam String name) { | ||
Issue11842Entity entity = new Issue11842Entity(); | ||
entity.setName(name); | ||
repository.persist(entity); | ||
return repository.findById(entity.getId()).getName(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...eployment/test/multiple_pu/repository/MultiplePersistenceUnitConfigForRepositoryTest.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,27 @@ | ||
package io.quarkus.hibernate.orm.panache.deployment.test.multiple_pu.repository; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.hibernate.orm.panache.deployment.test.multiple_pu.first.FirstEntity; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class MultiplePersistenceUnitConfigForRepositoryTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(Issue11842Entity.class, Issue11842Repository.class, Issue11842Resource.class, FirstEntity.class) | ||
.addAsResource("application-multiple-persistence-units-for-repository.properties", | ||
"application.properties")); | ||
|
||
@Test | ||
public void panacheOperations() { | ||
RestAssured.when().get("/repository/name-1").then().body(Matchers.is("name-1")); | ||
RestAssured.when().get("/repository/name-2").then().body(Matchers.is("name-2")); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...yment/src/test/resources/application-multiple-persistence-units-for-repository.properties
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,14 @@ | ||
quarkus.datasource.db-kind=h2 | ||
quarkus.datasource.jdbc.url=jdbc:h2:mem:default;DB_CLOSE_DELAY=-1 | ||
|
||
quarkus.datasource.repository.db-kind=h2 | ||
quarkus.datasource.repository.jdbc.url=jdbc:h2:mem:repository;DB_CLOSE_DELAY=-1 | ||
|
||
quarkus.hibernate-orm.dialect=org.hibernate.dialect.H2Dialect | ||
quarkus.hibernate-orm.database.generation=drop-and-create | ||
quarkus.hibernate-orm.packages=io.quarkus.hibernate.orm.panache.deployment.test.multiple_pu.first | ||
|
||
quarkus.hibernate-orm."repository".dialect=org.hibernate.dialect.H2Dialect | ||
quarkus.hibernate-orm."repository".database.generation=drop-and-create | ||
quarkus.hibernate-orm."repository".datasource=repository | ||
quarkus.hibernate-orm."repository".packages=io.quarkus.hibernate.orm.panache.deployment.test.multiple_pu.repository |