Hello,
I am having trouble with hibernate annotation. I can't get the TaskProp set in this Task object to populate.
@Entity @Table(name = "Task", uniqueConstraints = {@UniqueConstraint(columnNames={"type_id","name"})}) public class Task implements Serializable { @Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(name = "task_id") private long task_id;
@OneToMany(fetch = FetchType.LAZY, cascade=CascadeType.ALL ) //,mappedBy = "task" private Set<TaskProp> taskprops = new HashSet<TaskProp>(); //more code... }
and here is the taskprop class... @Entity @Table(name = "TaskProp", uniqueConstraints = @UniqueConstraint(columnNames = {"type_id","rank"})) public class TaskProp implements Serializable { @Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(name = "taskprop_id") private long taskprop_id;
private Task task;
@ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "task_id", nullable = false) public Task getTask() { return this.task; } //more code... }
Then I save it with something like this public void save(Task t, HashSet<TaskProp> taskprop){ Session session = sfact.getCurrentSession(); session.beginTransaction(); Iterator i = taskprop.iterator(); while(i.hasNext()){ TaskProp tp = (TaskProp) i.next(); tp.setTask(t); t.addTaskProp(tp); //do I need to do a session.save(tp)?? } session.save(t); session.getTransaction().commit(); }
Basically, I get no errors until I try to do a Task t; Set s = t.getTaskProps(); Everything in S is null when coming back from the db.
Thanks so much for your help! -Daniel Quest
|