[JIRA] (HHH-14129) Bidirectional relationship fails to save after upgrading to 5.4.17
by Eduardo Simioni (JIRA)
Eduardo Simioni ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNGJlZTUwOWU2... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-14129?atlOrigin=eyJpIjoiNGJlZT... ) HHH-14129 ( https://hibernate.atlassian.net/browse/HHH-14129?atlOrigin=eyJpIjoiNGJlZT... ) Bidirectional relationship fails to save after upgrading to 5.4.17 ( https://hibernate.atlassian.net/browse/HHH-14129?atlOrigin=eyJpIjoiNGJlZT... )
Change By: Eduardo Simioni ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
After updating upgrading from 5.4.16 to 5.4.17 we had several unit tests failing in one of our projects.
I did some investigation and came up with a minimum scenario and test case that reproduces the problem:
{code:java}
@Entity
public class Child {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotNull
@ManyToOne
private Parent parent;
public void setParent(Parent parent) {
this.parent = parent;
}
}
@Entity
public class Parent {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(cascade = CascadeType.ALL)
private Child child;
public Parent(Child child) {
this.child = child;
this.child.setParent(this);
}
public Child getChild() {
return child;
}
}
{code}
And a test case:
{code:java}
@ExtendWith(SpringExtension.class)
public class ParentChildTest {
@Test
@Transactional
public void save() {
Parent parent = new Parent(new Child());
sessionFactory.getCurrentSession().save(parent);
sessionFactory.getCurrentSession().setHibernateFlushMode(FlushMode.MANUAL);
sessionFactory.getCurrentSession().flush();
}
@Resource
private SessionFactory sessionFactory;
}
{code}
With 5.4.16 the following statements are executed and the test completes successfully
{code:sql}
insert into parent (id, child_id) values (null, ?)
insert into child (id, parent_id) values (null, ?)
update parent set child_id=? where id=?
{code}
With 5.4.17 the result is
{noformat}
DEBUG [SQL] insert into child (id, parent_id) values (null, ?)
WARN [SqlExceptionHelper] SQL Error: 23502, SQLState: 23502
ERROR [SqlExceptionHelper] NULL not allowed for column "PARENT_ID"; SQL statement:
insert into child (id, parent_id) values (null, ?) [23502-200]
{noformat}
If the @NotNulll annotation is removed the entities are saved without any problem, only in a different order
{code:sql}
insert into child (id, parent_id) values (null, ?)
insert into parent (id, child_id) values (null, ?)
update child set parent_id=? where id=?
{code}
# It seems to be related with the fix provided by [ HHH-10956 ]
*
( https://hibernate.atlassian.net/browse/HHH-14129#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-14129#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100140- sha1:5beb332 )
4 years, 5 months
[JIRA] (HHH-14129) Bidirectional relationship fails to save after updating to 5.4.17
by Eduardo Simioni (JIRA)
Eduardo Simioni ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiOGE2OTQyYzAy... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-14129?atlOrigin=eyJpIjoiOGE2OT... ) HHH-14129 ( https://hibernate.atlassian.net/browse/HHH-14129?atlOrigin=eyJpIjoiOGE2OT... ) Bidirectional relationship fails to save after updating to 5.4.17 ( https://hibernate.atlassian.net/browse/HHH-14129?atlOrigin=eyJpIjoiOGE2OT... )
Issue Type: Bug Affects Versions: 5.4.17 Assignee: Unassigned Components: hibernate-core Created: 30/Jul/2020 14:38 PM Environment: H2 Database in MySQL mode was used for the test Priority: Major Reporter: Eduardo Simioni ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
After updating from 5.4.16 to 5.4.17 we had several unit tests failing in one of our projects.
I did some investigation and came up with a minimum scenario and test case that reproduces the problem:
@Entity
public class Child {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotNull
@ManyToOne
private Parent parent;
public void setParent(Parent parent) {
this.parent = parent;
}
}
@Entity
public class Parent {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(cascade = CascadeType.ALL)
private Child child;
public Parent(Child child) {
this.child = child;
this.child.setParent( this );
}
public Child getChild() {
return child;
}
}
And a test case:
@ExtendWith(SpringExtension.class)
public class ParentChildTest {
@Test
@Transactional
public void save() {
Parent parent = new Parent( new Child());
sessionFactory.getCurrentSession().save(parent);
sessionFactory.getCurrentSession().setHibernateFlushMode(FlushMode.MANUAL);
sessionFactory.getCurrentSession().flush();
}
@Resource
private SessionFactory sessionFactory;
}
With 5.4.16 the following statements are executed and the test completes successfully
insert into parent (id, child_id) values ( null , ?)
insert into child (id, parent_id) values ( null , ?)
update parent set child_id=? where id=?
With 5.4.17 the result is
DEBUG [SQL] insert into child (id, parent_id) values (null, ?)
WARN [SqlExceptionHelper] SQL Error: 23502, SQLState: 23502
ERROR [SqlExceptionHelper] NULL not allowed for column "PARENT_ID"; SQL statement:
insert into child (id, parent_id) values (null, ?) [23502-200]
If the @NotNulll annotation is removed the entities are saved without any problem, only in a different order
insert into child (id, parent_id) values ( null , ?)
insert into parent (id, child_id) values ( null , ?)
update child set parent_id=? where id=?
It seems to be related with the fix provided by HHH-10956 ( https://hibernate.atlassian.net/browse/HHH-10956 ) Closed
( https://hibernate.atlassian.net/browse/HHH-14129#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-14129#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100140- sha1:5beb332 )
4 years, 5 months