Skip to content

Commit 3ebe0f1

Browse files
committed
HHH-9897 - @onetomany association with @JoinFormula throws NPE
(cherry picked from commit 53dfed4)
1 parent 7fba0e7 commit 3ebe0f1

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

hibernate-core/src/main/java/org/hibernate/cfg/Ejb3Column.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public void setUnique(boolean unique) {
182182
}
183183

184184
public boolean isNullable() {
185-
return mappingColumn.isNullable();
185+
return isFormula() ? true : mappingColumn.isNullable();
186186
}
187187

188188
public String getDefaultValue() {
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.test.annotations.formula;
8+
9+
import java.util.HashSet;
10+
import java.util.Set;
11+
import javax.persistence.Column;
12+
import javax.persistence.Entity;
13+
import javax.persistence.Id;
14+
import javax.persistence.OneToMany;
15+
import javax.persistence.Table;
16+
17+
import org.hibernate.SessionFactory;
18+
import org.hibernate.annotations.JoinColumnOrFormula;
19+
import org.hibernate.annotations.JoinColumnsOrFormulas;
20+
import org.hibernate.annotations.JoinFormula;
21+
import org.hibernate.boot.Metadata;
22+
import org.hibernate.boot.MetadataSources;
23+
import org.hibernate.boot.registry.StandardServiceRegistry;
24+
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
25+
26+
import org.hibernate.testing.FailureExpected;
27+
import org.hibernate.testing.TestForIssue;
28+
import org.hibernate.testing.junit4.BaseUnitTestCase;
29+
import org.junit.After;
30+
import org.junit.Before;
31+
import org.junit.Test;
32+
33+
/**
34+
* @author Steve Ebersole
35+
*/
36+
public class JoinColumnOrFormulaTest extends BaseUnitTestCase {
37+
private StandardServiceRegistry ssr;
38+
39+
@Before
40+
public void before() {
41+
ssr = new StandardServiceRegistryBuilder().build();
42+
}
43+
44+
@After
45+
public void after() {
46+
if ( ssr != null ) {
47+
StandardServiceRegistryBuilder.destroy( ssr );
48+
}
49+
}
50+
51+
@Test
52+
@TestForIssue( jiraKey = "HHH-9897" )
53+
@FailureExpected( jiraKey = "HHH-9897" )
54+
public void testUseOfJoinColumnOrFormula() {
55+
Metadata metadata = new MetadataSources()
56+
.addAnnotatedClass( A.class )
57+
.addAnnotatedClass( D.class )
58+
.buildMetadata();
59+
60+
// Binding to the mapping model works after the simple change for HHH-9897
61+
// But building the SessionFactory fails in the collection persister trying to
62+
// use the formula (it expects Columns too)
63+
metadata.buildSessionFactory().close();
64+
}
65+
66+
@Entity( name = "A" )
67+
@Table( name = "A" )
68+
public static class A {
69+
@Id
70+
@Column( name = "idA")
71+
public Integer id;
72+
73+
@OneToMany
74+
@JoinColumnsOrFormulas({
75+
@JoinColumnOrFormula(formula = @JoinFormula(value = "idA", referencedColumnName = "idA"))
76+
})
77+
Set<D> ds = new HashSet<D>();
78+
}
79+
80+
@Entity( name = "D" )
81+
@Table( name = "D" )
82+
public static class D {
83+
@Id
84+
@Column( name = "idA")
85+
public Integer idA;
86+
}
87+
}

0 commit comments

Comments
 (0)