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.  [ 7 posts ] 
Author Message
 Post subject: net.sf.hibernate.PropertyValueException
PostPosted: Wed Aug 11, 2004 2:03 am 
Newbie

Joined: Mon Aug 02, 2004 8:32 am
Posts: 16
I have a not-null property error and I think that there is something wrong with the mapping file but I can't find it.
The mapping is related one-to-many with a Table called component_part_type and it is also related one-to-many with another Table called component_part.
Furthermore our Table component_group is also related many-to-one with the table component_type.

Thank you for any help!


Hibernate version:
2.1.4

Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
           "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
   <class name="com.nokia.testbed.model.ComponentType" table="component_type">
      <id name="idComponentType" type="long" column="id_component_type">
         <generator class="sequence">
            <param name="sequence">component_type_sequence</param>
         </generator>
      </id>
      <property name="name" column="name" type="string" not-null="true"/>
      <property name="displayColor" column="display_color" type="string" not-null="true"/>
      <property name="description" column="description" type="string"/>
      <property name="otherConnectivity" column="has_other_connectivity" type="int"/>
      
                <set name="component" inverse="true">
         <key column="id_component_type"/>
         <one-to-many class="com.nokia.testbed.model.Component"/>
      </set>
               
      <set name="componentGroup" inverse="true">
         <key column="id_component_type"/>
         <one-to-many class="com.nokia.testbed.model.ComponentGroup"/>
      </set>


   </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
... has no errors ...

Full stack trace of any exception that occurs:
Code:
Hibernate: select component_group_sequence.nextval from dual
net.sf.hibernate.PropertyValueException: not-null property references a null or transient value: com.nokia.testbed.model.Compon
entGroup.componentType
        at net.sf.hibernate.impl.SessionImpl.checkNullability(SessionImpl.java:1276)
        at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:928)
        at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:857)
        at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:779)
        at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:738)
        at com.nokia.testbed.model.dbExecutor.insertComponentGroup(dbExecutor.java:248)
        at com.nokia.testbed.web.ComponentGroupAction.execute(ComponentGroupAction.java:60)
        at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
        at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
        at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
        at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2416)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
        at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
        at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:601)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
        at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
        at java.lang.Thread.run(Thread.java:534)




Name and version of the database you are using:
Oracle 8.1
Code:
[b]Debug level Hibernate log excerpt:[/b]
2004-08-11 07:53:43,235|Thread-5|DEBUG|net.sf.hibernate.impl.SessionImpl||opened session
2004-08-11 07:53:43,242|Thread-5|DEBUG|net.sf.hibernate.transaction.JDBCTransaction||begin
2004-08-11 07:53:43,243|Thread-5|DEBUG|net.sf.hibernate.connection.DriverManagerConnectionProvider||total checked-out connectio
ns: 0
2004-08-11 07:53:43,243|Thread-5|DEBUG|net.sf.hibernate.connection.DriverManagerConnectionProvider||using pooled JDBC connectio
n, pool size: 0
2004-08-11 07:53:43,244|Thread-5|DEBUG|net.sf.hibernate.transaction.JDBCTransaction||current autocommit status:false
2004-08-11 07:53:43,244|Thread-5|INFO |com.nokia.testbed.model.dbExecutor||#################### vor session.save() - insertComp
onentType ################ berni 5
2004-08-11 07:53:43,251|Thread-5|DEBUG|net.sf.hibernate.impl.BatcherImpl||about to open: 0 open PreparedStatements, 0 open Resu
ltSets
2004-08-11 07:53:43,252|Thread-5|DEBUG|net.sf.hibernate.SQL||select component_group_sequence.nextval from dual
2004-08-11 07:53:43,252|Thread-5|DEBUG|net.sf.hibernate.impl.BatcherImpl||preparing statement
2004-08-11 07:53:43,699|Thread-5|DEBUG|net.sf.hibernate.id.SequenceGenerator||Sequence identifier generated: 41
2004-08-11 07:53:43,700|Thread-5|DEBUG|net.sf.hibernate.impl.BatcherImpl||done closing: 0 open PreparedStatements, 0 open Resul
tSets
2004-08-11 07:53:43,700|Thread-5|DEBUG|net.sf.hibernate.impl.BatcherImpl||closing statement
2004-08-11 07:53:43,701|Thread-5|DEBUG|net.sf.hibernate.impl.SessionImpl||generated identifier: 41
2004-08-11 07:53:43,706|Thread-5|DEBUG|net.sf.hibernate.impl.SessionImpl||saving [com.nokia.testbed.model.ComponentGroup#41]
2004-08-11 07:53:43,740|Thread-5|DEBUG|net.sf.hibernate.transaction.JDBCTransaction||rollback
2004-08-11 07:53:43,741|Thread-5|DEBUG|net.sf.hibernate.impl.SessionImpl||transaction completion
2004-08-11 07:53:43,761|Thread-5|DEBUG|net.sf.hibernate.impl.SessionImpl||closing session
2004-08-11 07:53:43,762|Thread-5|DEBUG|net.sf.hibernate.impl.SessionImpl||disconnecting session
2004-08-11 07:53:43,768|Thread-5|DEBUG|net.sf.hibernate.connection.DriverManagerConnectionProvider||returning connection to poo
l, pool size: 1
2004-08-11 07:53:43,768|Thread-5|DEBUG|net.sf.hibernate.impl.SessionImpl||transaction completion
2004-08-11 07:53:43,769|Thread-5|DEBUG|org.apache.struts.tiles.TilesRequestProcessor||processForwardConfig(/WEB-INF/jsp/admin.j
sp, false)
2004-08-11 07:53:43,769|Thread-5|DEBUG|org.apache.struts.tiles.TilesRequestProcessor||  '/WEB-INF/jsp/admin.jsp' - processed as
uri
2004-08-11 07:53:43,770|Thread-5|DEBUG|org.apache.struts.action.RequestProcessor||processForwardConfig(ForwardConfig[name=succe
ss,path=/WEB-INF/jsp/admin.jsp,redirect=false,contextRelative=false])



Top
 Profile  
 
 Post subject: DB CODE
PostPosted: Wed Aug 11, 2004 2:05 am 
Newbie

Joined: Mon Aug 02, 2004 8:32 am
Posts: 16
my Database Code...

Code:
public static boolean insertComponentPartType(String aName,long aIdComponentGroup) throws Exception{
        Session session = HibernateUtil.currentSession();
        Transaction tx = session.beginTransaction();
        try{
            ComponentPartType c = new ComponentPartType();
            c.setName(aName);
            c.setIdComponentGroup(aIdComponentGroup);
            logger.info("#################### vor session.save() - insertComponentType ################ "+aName+" "+aIdComponentGroup);
            session.save(c); 
            logger.info("#################### nach session.save - insertComponentType ################");     
            tx.commit();
            logger.info("#################### after tx.commit() - insertComponentType ################");
            return true;
        }catch(Exception e){
            if(tx!=null)
            tx.rollback();
            e.printStackTrace();
            //return false;
            throw e;
           
        }finally{
            HibernateUtil.closeSession();
        }
    }



Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 2:13 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Mabe this helps:

Just before you call Session.save() in the method dbExecutor.insertComponentGroup() add a System.out.println() and dump the property values name and displayColor of any component type instance. I guess one of them is null. Of course you can do the same with a debugger.

HTH
Ernst


Top
 Profile  
 
 Post subject: one value is null
PostPosted: Wed Aug 11, 2004 2:37 am 
Newbie

Joined: Mon Aug 02, 2004 8:32 am
Posts: 16
I write three values to the Database and they are for example:
-name:xxdes
-id_component_type:null
-id_component_group:24 (sequence)

I don't know why hibernate tries to write null for id_component_type when I call session.save(c) because the method c.getIdComponentType() returns a correct value - for example: 5????

Thank you for any help!

Code:
public static boolean insertComponentGroup(String aName,long aIdComponentType) throws Exception{
        Session session = HibernateUtil.currentSession();
        Transaction tx = session.beginTransaction();
        try{
            ComponentGroup c = new ComponentGroup();
            c.setName(aName);
            c.setIdComponentType(aIdComponentType);
            logger.info("#################### vor session.save() - insertComponentType ################ "+aName+" "+aIdComponentType);                logger.info("#################### vor session.save - insertComponentType ################ TYPE: "+c.getIdComponentType());
            session.save(c); 
            logger.info("#################### nach session.save - insertComponentType ################ TYPE: "+c.getIdComponentType());     
            tx.commit();
            logger.info("#################### after tx.commit() - insertComponentType ################");
            return true;
        }catch(Exception e){
            if(tx!=null)
            tx.rollback();
            e.printStackTrace();
            return false;
            //throw e;
           
        }finally{
            HibernateUtil.closeSession();
        }
    }



Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 5:01 am 
Senior
Senior

Joined: Fri Nov 21, 2003 5:55 am
Posts: 155
Are you sure this part of mapping file is corretc?

<set name="componentGroup" inverse="true">
<key column="id_component_type"/>
<one-to-many class="com.nokia.testbed.model.ComponentGroup"/>
</set>

The key column name? You write this or it was generated by middlegen?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 5:24 am 
Newbie

Joined: Mon Aug 02, 2004 8:32 am
Posts: 16
The problem was that i made something wrong with the hibernate db action:

Here is the correct code: (I forgot to load the Parent Class)
Code:

public static boolean insertComponentGroup(String aName,long aIdComponentType) throws Exception{
        Session session = HibernateUtil.currentSession();
        Transaction tx = session.beginTransaction();
        try{
            ComponentType ct = (ComponentType)session.load(ComponentType.class,new Long(aIdComponentType));
            ComponentGroup c = new ComponentGroup();
            c.setName(aName);
            c.setIdComponentType(aIdComponentType);           
            c.setComponentType(ct);
            logger.info("ct.getComponentGroup().add(c);");
            ct.getComponentGroup().add(c);
            logger.info("before session save");

            logger.info("#################### vor session.save - insertComponentType ################ TYPE: "+c.getIdComponentType());
            session.save(c); 
            logger.info("#################### nach session.save - insertComponentType ################ TYPE: "+c.getIdComponentType());             
            tx.commit();
            logger.info("#################### after tx.commit() - insertComponentType ################");
            return true;
        }catch(Exception e){
            if(tx!=null)
            tx.rollback();
            e.printStackTrace();
            return false;
            //throw e;
           
        }finally{
            HibernateUtil.closeSession();
        }
    }



Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 5:29 am 
Senior
Senior

Joined: Fri Nov 21, 2003 5:55 am
Posts: 155
Now it's ok?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.