-->
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: ids for class must be manually assigned beforecalling save()
PostPosted: Fri Apr 09, 2010 2:36 am 
Newbie

Joined: Wed Mar 31, 2010 4:35 am
Posts: 19
I have two table

Xydataa and Fm4featuress

ID->PK
Fm4features

ID-PK-FK
DataId-pk

mapping file

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Apr 8, 2010 4:08:07 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="test.Xydataa" table="xydataa" catalog="navl">
<id name="id" type="java.lang.Integer">
<column name="ID" />
<generator class="identity" />
</id>
<property name="longi" type="string">
<column name="Longi" />
</property>
<property name="lat" type="string">
<column name="Lat" />
</property>
<property name="altitude" type="int">
<column name="Altitude" not-null="true" />
</property>
<property name="angle" type="int">
<column name="Angle" not-null="true" />
</property>
<property name="satellite" type="int">
<column name="Satellite" not-null="true" />
</property>
<property name="speed" type="int">
<column name="Speed" not-null="true" />
</property>
<property name="objectId" type="int">
<column name="ObjectId" not-null="true" />
</property>
<property name="clientId" type="int">
<column name="ClientId" not-null="true" />
</property>
<property name="gpsTime" type="string">
<column name="GpsTime" length="19" not-null="false" />
</property>
<property name="location" type="string">
<column name="Location" />
</property>
<property name="city" type="string">
<column name="City" />
</property>
<property name="state" type="string">
<column name="State" />
</property>
<property name="distance" type="string">
<column name="Distance" length="100" />
</property>
<property name="times" type="timestamp">
<column name="Times" length="19" not-null="false" />
</property>
<set name="objtablees" inverse="true">
<key>
<column name="ID" not-null="true" unique="true" />
</key>
<one-to-many class="test.Objtablee" />
</set>
<set name="fm4featuresses" cascade="all" inverse="true">
<key>
<column name="ID" not-null="true" />
</key>
<one-to-many class="test.Fm4featuress" />
</set>
</class>
</hibernate-mapping>


Fm4featuress.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Apr 8, 2010 4:08:07 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="test.Fm4featuress" table="fm4featuress" catalog="navl">
<composite-id name="id" class="test.Fm4featuressId">
<key-many-to-one name="id" class="test.Xydataa" column="ID" />
<key-property name="dataId" column="DataId"/>
</composite-id>
<property name="value" type="string">
<column name="Value" length="20" not-null="true" />
</property>
</class>
</hibernate-mapping>

Main Class

from open session to close session
Code:
sess = HibernateUtil.getSessionFactory().openSession();
             Date resultdate = new Date(times);
             xx = new DecimalNumber(x,7);
              yy = new DecimalNumber(y,7);
              System.out.println("Inserting xydataa");
              Xydataa xy=new Xydataa();
              Set set = new HashSet();
              xy.setLongi(xx+"");
              xy.setLat(yy+"");
              xy.setAltitude(altitude);
              xy.setAngle(angle);
              xy.setSatellite(satellites);
              xy.setSpeed(speed);
              xy.setObjectId(objectId);
              xy.setClientId(clientId);
              xy.setGpsTime(sdf.format(resultdate));
              xy.setLocation(location);
              xy.setCity(city);
              xy.setState(state);
              xy.setDistance(distance);
              System.out.println("Done");
              Fm4featuress fm = new  Fm4featuress();
              Fm4featuressId fm1 = new Fm4featuressId();
              for (int i = 0; i < obj.length && obj[i] != 0; i++)
             {
              int all = obj[i] - 1;
              System.out.println("Inserting Fm4Featuress");
              //fm.setId(0);
              fm1.setDataId(all);
              fm.setValue(obja[i]+"");
              fm.setXydataa(xy);
              xy.getFm4featuresses().add(fm);
              set.add(fm);
               //fm.setXydataa(xy);
              //set.add(fm);
              //xy.setFm4featuresses(set);
              System.out.println(set.contains(fm));
              System.out.println("***ID="+fm1.getId()+"***DataId="+fm1.getDataId()+"***Value="+fm.getValue());
             
              }

     Transaction transaction = null;
   try {
           transaction = sess.beginTransaction();
           sess.save(xy);
           sess.saveOrUpdate(fm);
           //sess.persist(fm);
           //sess.merge(fm);
           //sess.saveOrUpdate(fm);
           sess.flush();
           sess.clear();
           transaction.commit();
           System.out.println("Transaction commited");
      } catch (Exception e) {
         System.out.println("Exception Here");
           if (transaction != null) {
             transaction.rollback();
             throw e;
           }
      }  finally {
           if (sess!=null)
           {
               sess.close();
           }
      }

Error Stack Trace

org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): test.Fm4featuress
at org.hibernate.id.Assigned.generate(Assigned.java:33)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:99)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:94)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:507)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:499)
at org.hibernate.engine.CascadingAction$5.cascade(CascadingAction.java:218)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:296)
at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:242)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:219)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
at org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:456)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:334)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)


I got this error

Pls help any one me what ia m doing wrong

i need the ouput

Xydataa

1 4 5
2 4 8
5 8 0

Fm4featuress
ID DataID
1 3
1 5
1 8
1 ...
2
2
2
2
5
5
5
5


Advance Thanks


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.