Skip to content

reproducer for class cast https://discourse.hibernate.org/t/cannot-be-cast-to-cl… #514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
32 changes: 32 additions & 0 deletions orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/A.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.hibernate.bugs;

import org.hibernate.bugs.b.B;

import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType;

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class A {
@Id
protected long id;
protected String name;

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,27 @@
*/
class JPAUnitTestCase {

private EntityManagerFactory entityManagerFactory;
private EntityManagerFactory entityManagerFactory;

@BeforeEach
void init() {
entityManagerFactory = Persistence.createEntityManagerFactory( "templatePU" );
}
@BeforeEach
void init() {
entityManagerFactory = Persistence.createEntityManagerFactory("templatePU");
}

@AfterEach
void destroy() {
entityManagerFactory.close();
}
@AfterEach
void destroy() {
entityManagerFactory.close();
}

// Entities are auto-discovered, so just add them anywhere on class-path
// Add your tests, using standard JUnit.
@Test
void hhh123Test() throws Exception {
EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
// Do stuff...
entityManager.getTransaction().commit();
entityManager.close();
}
// Entities are auto-discovered, so just add them anywhere on class-path
// Add your tests, using standard JUnit.
@Test
void hhh123Test() throws Exception {
EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
// Do stuff...
A a = entityManager.find(A.class, 1L);
entityManager.getTransaction().commit();
entityManager.close();
}
}
31 changes: 31 additions & 0 deletions orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/b/B.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.hibernate.bugs.b;

import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType;
import org.hibernate.bugs.A;

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class B extends A{
@Id
protected long id;
protected String bname;

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public String getBname() {
return bname;
}

public void setBname(String bname) {
this.bname = bname;
}
}