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.  [ 1 post ] 
Author Message
 Post subject: Hibernate throwing exception on insert on one-to-many
PostPosted: Wed Apr 10, 2013 10:06 am 
Newbie

Joined: Wed Mar 13, 2013 6:59 am
Posts: 3
Hello, I have the following DB tables:

Code:
CREATE TABLE DS_NVALUES(
  id Number NOT NULL,
  value1 Number(3,0),
  value2 Number(3,0),
  CONSTRAINT ds_nvalues_id PRIMARY KEY (id)
)

CREATE TABLE DS_AREA(
  id Number NOT NULL,
  id_nvalues Varchar2(15),
  n_c Number(4,0), 
  CONSTRAINT ds_area_id PRIMARY KEY (id)
)


One DSNValue can has a list of DSAreas.
These are the mapping files:

Code:
<hibernate-mapping package="es.entities">
   <class name="DSValues" table="ds_nvalues" lazy="false">
      <id name="id" column="id">
         <generator class="org.hibernate.id.MultipleHiLoPerTableGenerator">
            <param name="table">igea_codigos</param>
            <param name="primary_key_column">nombre</param>
            <param name="value_column">codigo</param>
            <param name="primary_key_value">ds_nvalues</param>
            <param name="max_lo">0</param>
         </generator>
      </id>      
      <property name="value1" column="value1"/>
      <property name="value2" column="value2"/>

      <property name="codedId" formula="encode_id('ds_nvalues', id)"/>

      <bag name="areas" table="ds_area" cascade="save-update, delete" fetch="select" lazy="false" inverse="true" >
         <key property-ref="codedId">
            <column name="id_nvalues"/>
         </key>
         <one-to-many class="es.entities.DSArea" not-found="exception" />
      </bag>

   </class>
</hibernate-mapping>



<hibernate-mapping package="es.entities">
   <class name="DSArea" table="ds_area" lazy="false">
      <id name="id" column="id">
         <generator class="org.hibernate.id.MultipleHiLoPerTableGenerator">
            <param name="table">igea_codigos</param>
            <param name="primary_key_column">nombre</param>
            <param name="value_column">codigo</param>
            <param name="primary_key_value">ds_area</param>
            <param name="max_lo">0</param>
         </generator>
      </id>
      <property name="n_c" column="n_c"/>

      <many-to-one name="dsValues" class="es.entities.DSValues"  unique="true" fetch="select">
         <column name="id_nvalues" write="encode_id('ds_nvalues', ?)"            read="decode_id(id_nvalues)"/>
      </many-to-one>
   </class>
</hibernate-mapping>


And when I create a new DSNValue I hace the following code:

Code:
DSArea area1 = new DSArea();
area1.setN_c(300);
List<DSArea> areas = new ArrayList<DSArea>();
areas.add(area1);

DSValues dsValues = new DSValues();
dsValues.setValue1(3);
dsValues.setValue2(4);
dsValues.setAreas(areas);
area1.setDsValues(dsValues);

Session session = getCurrentSession();
Transaction t = session.beginTransaction();      
try{
   session.save(dsValues);
   t.commit();
}catch(Exception e){
   t.rollback();         
}


t.commit throws a NullPointerException, but in the hibernate log I can see the INSERT statements an its values and they are ok. For selecting the DB elements this mapping configuration works fine. What can be happening?

Code:
java.lang.NullPointerException   at org.hibernate.type.descriptor.java.AbstractTypeDescriptor.extractHashCode(AbstractTypeDescriptor.java:88)
at org.hibernate.type.AbstractStandardBasicType.getHashCode(AbstractStandardBasicType.java:210)
at org.hibernate.type.AbstractStandardBasicType.getHashCode(AbstractStandardBasicType.java:214)
at org.hibernate.engine.spi.CollectionKey.generateHashCode(CollectionKey.java:86)
at org.hibernate.engine.spi.CollectionKey.<init>(CollectionKey.java:74)
at org.hibernate.engine.spi.CollectionKey.<init>(CollectionKey.java:50)
at org.hibernate.event.internal.AbstractFlushingEventListener.postFlush(AbstractFlushingEventListener.java:369)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:53)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1233)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:403)
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175)
at es.indra.rbc.da.impl.oracle.dao.OracleElementDAO.insert(OracleElementDAO.java:51)


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

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.