-->
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: Newbie - problem saving collections
PostPosted: Thu Oct 30, 2008 10:36 am 
Regular
Regular

Joined: Tue Apr 10, 2007 10:02 am
Posts: 56
I'm getting a hibernate mapping exception each time I try to save an entity that has collections...

Here's the Java class...
Code:
public class ServiceEntry extends VersionedAliasTitledEntity {

   private static final long serialVersionUID = 3881126332255299362L;

   private String fShortDesc;
   private String fLongDesc;
   private boolean fDisabled = false;
   private boolean fPublished = false;
   private boolean fPublicOwned = true;
   private java.util.Date fCreated;
   
   private List<String> fAlternativeTitles = new ArrayList<String>();
   private List<String> fKeywords = new ArrayList<String>();
   
   public ServiceEntry() {
   }




And the related mapping file...
Code:
   <class name="com.eis.service.definition.ServiceEntry" table="service_entry">
      <id name="ID" type="java.lang.Integer"  unsaved-value="-1">
         <column name="ServiceEntryIntID" />
         <generator class="native" />
      </id>

      <version name="version" type="integer" column="ServiceEntryVersion" />

      <property name="title" type="java.lang.String">
         <column name="ServiceEntryTitle" length="50" not-null="true"
            unique="true" />
      </property>
      <property name="alias" type="java.lang.String">
         <column name="ServiceEntryAlias" length="50" />
      </property>
      <property name="shortDesc" type="java.lang.String">
         <column name="ServiceEntryShortDesc" length="100" />
      </property>
      <property name="longDesc" type="java.lang.String">
         <column name="ServiceEntryLongDesc" length="65535" />
      </property>
      <property name="disabled" type="java.lang.Boolean">
         <column name="ServiceEntryDisabled" />
      </property>
      <property name="published" type="java.lang.Boolean">
         <column name="ServiceEntryPublished" />
      </property>
      <property name="publicOwned" type="java.lang.Boolean">
         <column name="ServiceEntryPublicOwnership" />
      </property>
      <property name="created" type="java.util.Date">
         <column name="ServiceEntryCreated" length="0" />
      </property>
      <idbag name="alternativeTitles" lazy="true"
         table="alternative_title" >
         <collection-id type="java.lang.Integer" column="AltTitleIntID">
            <generator class="native" />
         </collection-id>
         <key column="ServiceEntryIntID"/>
         <element type="string" column="AlternativeTitle"  />
      </idbag>
      <idbag name="keywords" lazy="true"
         table="service_entry_keyword">
         <collection-id type="java.lang.Integer" column="KeywordIntID">
            <generator class="native" />
         </collection-id>
         <key column="ServiceEntryIntID"/>
         <element type="string" column="Keyword" />
      </idbag>
   </class>



and the schema....
Code:
CREATE TABLE `service_entry` (
  `ServiceEntryIntID` int(11) NOT NULL auto_increment,
  `ServiceEntryTitle` varchar(50) NOT NULL,
  `ServiceEntryAlias` varchar(50) default NULL,
  `ServiceEntryShortDesc` varchar(100) default NULL,
  `ServiceEntryLongDesc` text,
  `ServiceEntryDisabled` tinyint(1) default '0',
  `ServiceEntryPublished` tinyint(1) default '0',
  `ServiceEntryPublicOwnership` tinyint(1) default '1',
  `ServiceEntryCreated` timestamp NULL default CURRENT_TIMESTAMP,
  `ServiceEntryVersion` int(11) default NULL,
  PRIMARY KEY  (`ServiceEntryIntID`),
  UNIQUE KEY `service_entry_title` (`ServiceEntryTitle`),
  KEY `service_entry_alias` (`ServiceEntryAlias`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;

CREATE TABLE `alternative_title` (
  `AltTitleIntID` int(11) NOT NULL auto_increment,
  `AlternativeTitle` varchar(50) default NULL,
  `ServiceEntryIntID` int(11) NOT NULL,
  PRIMARY KEY  (`AltTitleIntID`),
  KEY `fk_alternative_service_title` (`ServiceEntryIntID`),
  CONSTRAINT `fk_alternative_service_title` FOREIGN KEY (`ServiceEntryIntID`) REFERENCES `service_entry` (`ServiceEntryIntID`) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `service_entry_keyword` (
  `KeywordIntID` int(11) NOT NULL auto_increment,
  `Keyword` varchar(50) default NULL,
  `ServiceEntryIntID` int(11) NOT NULL,
  PRIMARY KEY  (`KeywordIntID`),
  KEY `fk_service_entry_keyword_service_entry` (`ServiceEntryIntID`),
  CONSTRAINT `fk_service_entry_keyword_service_entry` FOREIGN KEY (`ServiceEntryIntID`) REFERENCES `service_entry` (`ServiceEntryIntID`) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


This is the exception dump....
Code:
22637 [main] INFO type.IntegerType  - could not bind value 'POST_INSERT_INDICATOR' to parameter: 2; org.hibernate.id.IdentifierGeneratorFactory$2
22642 [main] ERROR definition.ServiceEntryManagerImpl  - ServiceEntryManagerImpl.add method failed with persistence exception
com.eis.exception.PersistenceException: Module name [ServiceEntry]
Module error number [2]
Persistence error saving new service entry
   at com.eis.service.definition.ServiceEntryDAOImpl.add(ServiceEntryDAOImpl.java:87)
   at com.eis.service.definition.ServiceEntryManagerImpl.add(ServiceEntryManagerImpl.java:61)
   at data.BuildDevData.createServiceEntries(BuildDevData.java:165)
   at data.BuildDevData.buildAllData(BuildDevData.java:199)
   at data.BuildDevData.execute(BuildDevData.java:210)
   at data.BuildDevData.main(BuildDevData.java:219)
Caused by: java.lang.ClassCastException: org.hibernate.id.IdentifierGeneratorFactory$2
   at org.hibernate.type.IntegerType.set(IntegerType.java:41)
   at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
   at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:116)
   at org.hibernate.persister.collection.AbstractCollectionPersister.writeIdentifier(AbstractCollectionPersister.java:807)
   at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1138)
   at org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:26)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:145)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
   at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:390)
   at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:420)
   at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
   at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:690)
   at com.eis.service.definition.ServiceEntryDAOImpl.add(ServiceEntryDAOImpl.java:84)
   ... 5 more
com.eis.exception.PersistenceException: Module name [ServiceEntry]
Module error number [2]
Persistence error saving new service entry
   at com.eis.service.definition.ServiceEntryDAOImpl.add(ServiceEntryDAOImpl.java:87)
   at com.eis.service.definition.ServiceEntryManagerImpl.add(ServiceEntryManagerImpl.java:61)
   at data.BuildDevData.createServiceEntries(BuildDevData.java:165)
   at data.BuildDevData.buildAllData(BuildDevData.java:199)
   at data.BuildDevData.execute(BuildDevData.java:210)
   at data.BuildDevData.main(BuildDevData.java:219)
Caused by: java.lang.ClassCastException: org.hibernate.id.IdentifierGeneratorFactory$2


Any ideas?
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 30, 2008 11:17 pm 
Regular
Regular

Joined: Tue Apr 10, 2007 10:02 am
Posts: 56
Changing the idbag collection generator class from 'native' to 'increment' fixes the problem.

from...
Code:
      <idbag name="alternativeTitles" lazy="true"
         table="alternative_title" >
         <collection-id type="integer" column="AltTitleIntID">
            <generator class="native" />
         </collection-id>
         <key column="ServiceEntryIntID" />
         <element type="string" column="AlternativeTitle"  />
      </idbag>



...to...
Code:
      <idbag name="alternativeTitles" lazy="true"
         table="alternative_title" >
         <collection-id type="integer" column="AltTitleIntID">
            <generator class="increment" />
         </collection-id>
         <key column="ServiceEntryIntID" />
         <element type="string" column="AlternativeTitle"  />
      </idbag>



... fixes the problem.
[/code]


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.