Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 2.17
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
Strange problem. My DAO layer is using Hibernate. I retrieve a POJO "Task" from the DAO. It has a Set which contains POJOs of type "TaskJob" (Task is parent of TaskJob).
I define a new TaskJob, set its parent to the Task I have retrieved; and then add it in the Set of the Task I have retrieved. Now I do not call the save method of my DAO and just commit the transaction. I expect Hibernate not to save it as I should call the save method of my DAO explicitly. What happening is Hibernate is saving it.
Can someboddy please explain? Thanks
This is my script :
String taskName = "Task A";
try {
HibernateUtil.getSession();
HibernateUtil.beginTransaction();
// creates a SchedulerDAOFactory
SchDAOFactory aSchDAOFactory = SchDatastoreSelector.getSchDAOFactory();
// creates a TaskDAO
TaskDAO aTaskDAO = aSchDAOFactory.getTaskDAO();
// retrieve the Task whose Name = ? and display it
Task aTask = aTaskDAO.getTaskByTaskName( taskName );
Set aTask_TaskJobs = aTask.getTaskJobs();
// define a new TaskJob for this Task
TaskJob aTaskJob = new TaskJob();
aTaskJob.setJob( new Integer(1) );
aTaskJob.setTask( aTask );
// add this new TaskJob to this Task
aTask_TaskJobs.add( aTaskJob );
HibernateUtil.commitTransaction();
}
catch (InfrastructureException iex) {
System.out.println( "index.jsp: iex.getMessage() = " + iex.getMessage() );
HibernateUtil.rollbackTransaction();
}
finally {
HibernateUtil.closeSession();
}