Fix null constraint violation issue introduced in previous commit

This commit is contained in:
Christian Beikov 2023-01-11 12:07:33 +01:00
parent ce0084cf18
commit c402431b9f
1 changed files with 17 additions and 7 deletions

View File

@ -38,9 +38,9 @@ public class HqlSubselectParameterTest {
public void setUp(SessionFactoryScope scope) { public void setUp(SessionFactoryScope scope) {
scope.inTransaction( scope.inTransaction(
session -> { session -> {
Resource resource = new Resource(); Resource resource = new Resource( 1L, null );
session.persist( resource ); session.persist( resource );
Bookmark bookmark = new Bookmark(); Bookmark bookmark = new Bookmark( 1L, null );
session.persist( bookmark ); session.persist( bookmark );
} }
@ -53,7 +53,7 @@ public class HqlSubselectParameterTest {
session -> { session -> {
String query = "select rsrc, (select count(mrk.key) from bookmark as mrk where mrk.key=:identityKey) as myBookmarks from resource as rsrc"; String query = "select rsrc, (select count(mrk.key) from bookmark as mrk where mrk.key=:identityKey) as myBookmarks from resource as rsrc";
List<Object[]> objects = session.createQuery( query, Object[].class ) List<Object[]> objects = session.createQuery( query, Object[].class )
.setParameter( "identityKey", 100l ) .setParameter( "identityKey", 100L )
.getResultList(); .getResultList();
assertThat( objects.size() ).isEqualTo( 1 ); assertThat( objects.size() ).isEqualTo( 1 );
@ -64,24 +64,34 @@ public class HqlSubselectParameterTest {
@Entity(name = "bookmark") @Entity(name = "bookmark")
@Table(name = "o_bookmark") @Table(name = "o_bookmark")
public static class Bookmark { public static class Bookmark {
@Id @Id
@Column(name = "id", nullable = false, unique = true, updatable = false) @Column(name = "id", nullable = false, unique = true, updatable = false)
private Long key; private Long key;
private String name; private String name;
public Bookmark() {
}
public Bookmark(Long key, String name) {
this.key = key;
this.name = name;
}
} }
@Entity(name = "resource") @Entity(name = "resource")
@Table(name = "o_resource") @Table(name = "o_resource")
public static class Resource { public static class Resource {
@Id @Id
@Column(name = "id", nullable = false, unique = true, updatable = false) @Column(name = "id", nullable = false, unique = true, updatable = false)
private Long key; private Long key;
private String name; private String name;
public Resource() {
}
public Resource(Long key, String name) {
this.key = key;
this.name = name;
}
} }
} }