Hi,
I am trying the one-to-many relationship in hibernate and am getting the following error ,
Quote:
[6/28/07 12:36:50:704 IST] 13cc2959 AbstractFlush E org.hibernate.event.def.AbstractFlushingEventListener Could not synchronize database state with session
[6/28/07 12:36:50:766 IST] 13cc2959 AbstractFlush E org.hibernate.event.def.AbstractFlushingEventListener TRAS0014I: The following exception was logged org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.coalesce.vo.COLTask
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:219)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:397)
at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:78)
at org.hibernate.persister.collection.AbstractCollectionPersister.writeElement(AbstractCollectionPersister.java:755)
at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1143)
at org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:26)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:143)
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:387)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:368)
at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:681)
I have a two table Projects and Tasks and I need a relation ship between the two,
Quote:
<class name="com.coalesce.vo.COLProject" table="col_projects" lazy="true">
<id column="projectid" name="projectId" type="java.lang.Long">
<generator class="sequence">
<param name="sequence">col_projects_seq</param>
</generator>
</id>
<property column="project_name" name="projectName" type="java.lang.String" />
<property column="project_code" name="projectCode" type="java.lang.String"/>
<property column="created_on" name="createdOn" type="timestamp" />
<property column="updated_on" name="updatedOn" type="timestamp"/>
<property column="created_by" name="createdBy" type="java.lang.String" />
<property column="updated_by" name="updateBy" type="java.lang.String"/>
<set name="tasks">
<key column="projectid" not-null="true"/>
<one-to-many class="com.coalesce.vo.COLTask"/>
</set>
</class>
Task
Quote:
<class name="com.coalesce.vo.COLTask" table="col_tasks">
<id column="task_id" name="taskId" type="java.lang.Long">
<generator class="sequence">
<param name="sequence">col_tasks_seq</param>
</generator>
</id>
<property column="task_name" name="taskName" type="java.lang.String" />
<property column="task_desc" name="taskDesc" type="java.lang.String"/>
<property column="RTS_no" name="rtsNo" type="integer" />
<property column="estimatedStartdate" name="estimatedStartdate" type="date"/>
<property column="estimatedEndDate" name="estimatedEndDate" type="date" />
<property column="actualStartDate" name="actualStartDate" type="date"/>
<property column="actualEndDate" name="actualEndDate" type="date"/>
<property column="createdBy" name="createdBy" type="java.lang.String"/>
<property column="created_on" name="createdOn" type="timestamp"/>
</class>
I am trying to do the following in code,
Code:
COLProject project = projectDAO.getProject(new Long(8));
COLTask task = new COLTask();
task.setTaskName("Rohit");
task.setTaskDesc("Description is not important");
task.setRtsNo(1256);
task.setEstimatedStartdate(new Date());
task.setEstimatedStartdate(new Date());
task.setActualEndDate(new Date());
task.setActualStartDate(new Date());
task.setCreatedBy("Rohit");
task.setCreatedOn(timeHelp.getTimestamp());
tasks.add(task);
project.setTasks(tasks);
projectDAO.saveProject(project);
Thanks,
Rohit