Hibernate version:
Hibernate Core 3.3.1 GA
HIbernate Annotations 3.4.0 GA
Mapping documents:
Code:
public class QueryDefinition {
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
@JoinColumn(name = "qLibraryId", nullable=false)
@ForeignKey(name = "fk_QueryDefinition_QueryLibrary")
public QueryLibrary getQueryLibrary() {
return queryLibrary;
}
}
public class QueryLibrary {
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy="queryLibrary")
@BatchSize(size = 25)
public Set<QueryDefinition> getQueryDefinitions() {
return this.queryDefinitions;
}
}
Code between sessionFactory.openSession() and session.close():This is calling code that causes the error/stacktrace.
Code:
public QueryLibrary[] findAllQueryLibraries() {
List<QueryLibrary> qlibs = (List) hibTempl.execute(new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException {
Query query = session.getNamedQuery("findAllQueryLibraries");
return query.list();
}
});
return qlibs.toArray(new QueryLibrary[qlibs.size()]);
}
And this is the HQL query being called:
Code:
@NamedQuery(name="findAllQueryLibraries", query="FROM com.vamosa.query.QueryLibrary ql"),
Full stack trace of any exception that occurs:Code:
[junit] Testcase: testCreateMasterProject took 0.604 sec
[junit] Caused an ERROR
[junit] not-null property references a null or transient value: com.vamosa.query.QueryDefinition.queryLibrary; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value: com.vamosa.query.QueryDefinition.queryLibrary
[junit] org.springframework.dao.DataIntegrityViolationException: not-null property references a null or transient value: com.vamosa.query.QueryDefinition.queryLibrary; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value: com.vamosa.query.QueryDefinition.queryLibrary
[junit] Caused by: org.hibernate.PropertyValueException: not-null property references a null or transient value: com.vamosa.query.QueryDefinition.queryLibrary
[junit] at org.hibernate.engine.Nullability.checkNullability(Nullability.java:95)
[junit] at org.hibernate.event.def.DefaultFlushEntityEventListener.scheduleUpdate(DefaultFlushEntityEventListener.java:292)
[junit] at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:151)
[junit] at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219)
[junit] at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)
[junit] at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:58)
[junit] at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:996)
[junit] at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1141)
[junit] at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
[junit] at com.vamosa.query.QueryLibrarianServiceImpl$2.doInHibernate(QueryLibrarianServiceImpl.java:126)
Name and version of the database you are using:
Derby 10.4
The Problem:
I've got two entities QueryLibrary (parent) and QueryDefinition (child) in a bi-directional OneToMany relationship. When the @JoinColumn is set to nullable=true querying the empty tables works, when @JoinColumn is set to nullable=false querying the empty tables causes the above error. Also if I put some data into the two underlying tables @JoinColumn set to nullable=false works.
I can understand the error condition
not-null property references a null or transient value: com.vamosa.query.QueryDefinition.queryLibrary
if there somehow were some existing QueryDefinition records in the DB unrelated to any QueryLibrary. But in my case there are no records in the DB at all.
Any help would be greatly appreciated,
Ijonas.