-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
AssertionError in EntityInitializerImpl.resolveInstanceSubInitializers after upgrading to 3.14 #43296
Comments
/cc @FroMage (panache), @loicmathieu (panache) |
cc @yrodiere |
Thanks for reporting. Can you please provide a reproducer (a small project that exhibits the issue)? |
@yrodiere That's the problem, I dont know exactly how to reproduce it. I'm going through that code at other places without issue so it must be some internal Hibernate state. |
Might be a side effect from having other entities already loaded in the same session. You're going to have to iterate: remove code, check it still fails, repeat :/ |
It's definitely related to loading another entity with a |
On 6.6.0 i sometimes get:
on 6.5.2 the issue is not present. |
@cmadsen Thanks for reporting. A reproducer would help a lot :) |
String id = manyToOneRelation.getXYZ().getId();
getCurrentSession().delete(manyToOneRelation);
getCurrentSession().get(XYZ.class, id); |
Nope, that works: yrodiere/hibernate-test-case-templates@291cead
I'm afraid there's a little more to it than 3 lines of code. Please provide an actual reproducer? |
@yrodiere @cmadsen |
Alright, thanks for the heads-up!
|
This will reproduce it, but only with the right compiler options. @Entity
@Cacheable
public class Child {
@Id
private Long id;
@OneToMany(mappedBy = "child")
@OrderColumn
@Cache(usage = NONSTRICT_READ_WRITE)
List<ManyToMany> children = new ArrayList<>();
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public List<ManyToMany> getChildren() {
return children;
}
public void setChildren(List<ManyToMany> children) {
this.children = children;
}
}
@Entity
@Cacheable
public class Parent {
@Id
private Long id;
@OneToMany(mappedBy = "parent")
@Cache(usage = NONSTRICT_READ_WRITE)
@LazyCollection(LazyCollectionOption.FALSE)
List<ManyToMany> children = new ArrayList<>();
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public List<ManyToMany> getChildren() {
return children;
}
public void setChildren(List<ManyToMany> children) {
this.children = children;
}
}
@Entity
public class ManyToMany {
@Id
private Long id;
@ManyToOne
private Parent parent;
@ManyToOne
private Child child;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Parent getParent() {
return parent;
}
public void setParent(Parent parent) {
this.parent = parent;
}
public Child getChild() {
return child;
}
public void setChild(Child child) {
this.child = child;
}
}
@Transactional
public class Dao {
SessionFactory sessionFactory;
public Dao(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public void save(Object o) {
sessionFactory.getCurrentSession().save(o);
}
public List<Object> getAll(Class c) {
Session session = sessionFactory.getCurrentSession();
CriteriaBuilder cb = session.getCriteriaBuilder();
CriteriaQuery<Object> query = cb.createQuery(c);
Root<Object> root = query.from(c);
return session.createQuery(query).getResultList();
}
public void doInSession(Consumer<Session> s) {
s.accept(sessionFactory.getCurrentSession());
}
}
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { TestHib6.TestConfig.class })
public class TestHib6 {
@Autowired
SessionFactory sessionFactory;
@Autowired
Dao dao;
@Test
public void testHib6Step1() {
try {
Parent p = new Parent();
p.setId(1L);
Child c = new Child();
c.setId(2L);
ManyToMany m = new ManyToMany();
m.setId(3L);
m.setParent(p);
m.setChild(c);
p.setChildren(Arrays.asList(m));
c.setChildren(Arrays.asList(m));
dao.save(p);
dao.save(c);
dao.save(m);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testHib6Step2() {
try {
ManyToMany m = (ManyToMany) dao.getAll(ManyToMany.class).get(0);
assertThat(m, is(notNullValue()));
assertThat(m.getId(), is(3L));
dao.doInSession(s -> {
s.delete(m);
Parent p = s.get(Parent.class, 1);
Child c = s.get(Child.class, 2);
System.out.println("id=" + p.getId() + " c.id=" + c.getId());
});
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Configuration
@EnableTransactionManagement
static class TestConfig {
static private final String H2_JDBC_URL = "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DATABASE_TO_LOWER=true;"
+ "DEFAULT_NULL_ORDERING=HIGH;CASE_INSENSITIVE_IDENTIFIERS=FALSE"
+ ";TRACE_LEVEL_SYSTEM_OUT=1;NON_KEYWORDS=VALUE,YEAR,MONTH;MODE=PostgreSQL";
@Bean
protected DataSource dataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName("org.h2.Driver");
dataSource.setUrl(H2_JDBC_URL);
return dataSource;
}
@Bean
public PlatformTransactionManager transactionManager(
SessionFactory sessionFactory) {
return new HibernateTransactionManager(sessionFactory);
}
@Bean
protected LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean factoryBean = new LocalSessionFactoryBean();
try {
Properties pp = new Properties();
pp.setProperty("hibernate.dialect",
"org.hibernate.dialect.PostgreSQLDialect");
pp.setProperty("hibernate.hbm2ddl.auto", "create");
pp.setProperty("hibernate.show_sql", "true");
pp.setProperty("hibernate.format_sql", "false");
pp.setProperty("hibernate.use_sql_comments", "true");
pp.setProperty("hibernate.cache.use_second_level_cache",
"false");
pp.setProperty("hibernate.generate_statistics", "true");
pp.setProperty("hibernate.cache.use_query_cache", "false");
factoryBean.setDataSource(dataSource());
factoryBean
.setPackagesToScan("test.hib6");
factoryBean.setHibernateProperties(pp);
factoryBean.afterPropertiesSet();
} catch (Exception e) {
e.printStackTrace();
}
return factoryBean;
}
@Bean
public Dao dao() {
return new Dao(sessionFactory().getObject());
}
}
} |
Thanks. Reported as https://hibernate.atlassian.net/browse/HHH-18631. |
A fix has already been made. Do you know how to test locally if it's now working? My use case is a bit different (only read, no delete) so I would like to try it myself. |
Right now you won't be able to, because the fix is targeting Hibernate ORM's
FWIW, if your use case is read only, it might already be fixed with 6.6.1 (https://hibernate.atlassian.net/browse/HHH-18565), which we'll be upgrading to soon: #43348 . That should be easier for you to test. |
@yrodiere Actually I forced hibernate-core to 6.6.1 and it indeed works in my case. |
https://hibernate.atlassian.net/browse/HHH-18631 was fixed in ORM 6.6.2, so this will get fixed once 6.6.2 is released and we upgrade. |
Describe the bug
After upgrading to Quarkus 3.14 I'm getting this error on a Panache "list" operation:
It's probably related to the underlying Hibernate 6.6 upgrade but I cannot understand why. The assertion is expection a "Status.LOADING" but if I put a breakpoint here I have "Status.MANAGED".
Expected behavior
No response
Actual behavior
No response
How to Reproduce?
No response
Output of
uname -a
orver
No response
Output of
java -version
No response
Quarkus version or git rev
3.14.4
Build tool (ie. output of
mvnw --version
orgradlew --version
)No response
Additional information
No response
The text was updated successfully, but these errors were encountered: