-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Empty table causes infamous null or transient value error
PostPosted: Mon Oct 20, 2008 3:09 am 
Newbie

Joined: Thu Dec 09, 2004 9:03 am
Posts: 2
Location: Glasgow, United Kingdom
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.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 20, 2008 3:57 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
The problem is not related to the query as such or if something is in the database or not, but to the automatic flush that Hibernate issues before the query. It indicates that you have done something else in your session that Hibernate is now trying to save to the database. From the error message it seems like there is a new or modified QueryDefinition object related to the same session that has a null or transient QueryLibrary attached to it.

So check your code and see if you can find what is going on before you call the findAllQueryLibraries() method. Then, you can possibly re-arrange the order you are doing things or set a different flush mode on the session, for example, session.setFlushMode(FlushMode.COMMIT).


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.