Skip to content

Commit

Permalink
Regression test for issue #16860 resolved by HHH-14575
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanne committed Apr 30, 2021
1 parent cdbf656 commit c3dd446
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.quarkus.it.jpa.h2.basicproxy;

import java.io.Serializable;
import java.util.Objects;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "ENTITY")
@DiscriminatorColumn(name = "TYPE")
public abstract class AbstractEntity implements Serializable {

public AbstractEntity() {
// nop
}

@Id
@Column(name = "TYPE", insertable = false, updatable = false)
public String type;

@Id
@Column(name = "ID")
public String id;

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
AbstractEntity that = (AbstractEntity) o;
return Objects.equals(type, that.type) && Objects.equals(id, that.id);
}

@Override
public int hashCode() {
return Objects.hash(type, id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.quarkus.it.jpa.h2.basicproxy;

import java.io.IOException;
import java.util.List;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.transaction.Transactional;

import io.quarkus.runtime.StartupEvent;

@ApplicationScoped
@WebServlet(urlPatterns = "/jpa-h2/testbasicproxy")
public class BasicProxyTestEndpoint extends HttpServlet {

@Inject
EntityManager entityManager;

@Transactional
public void setup(@Observes StartupEvent startupEvent) {
ConcreteEntity entity = new ConcreteEntity();
entity.id = "1";
entity.type = "Concrete";
entityManager.persist(entity);
}

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
final List list = entityManager.createQuery("from ConcreteEntity").getResultList();
if (list.size() != 1) {
throw new RuntimeException("Expected 1 result, got " + list.size());
}
resp.getWriter().write("OK");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.quarkus.it.jpa.h2.basicproxy;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;

@Entity
@DiscriminatorValue("Concrete")
public class ConcreteEntity extends AbstractEntity {

public ConcreteEntity() {
super();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ public void testHibernateEnhancedProxies() throws Exception {
RestAssured.when().get("/jpa-h2/testproxy").then().body(is("OK"));
}

@Test
public void testHibernateEnhancedBasicProxies() throws Exception {
RestAssured.when().get("/jpa-h2/testbasicproxy").then().body(is("OK"));
}

}

0 comments on commit c3dd446

Please sign in to comment.