-->
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: Trouble with inverse mapping.
PostPosted: Tue Feb 08, 2011 3:23 pm 
Newbie

Joined: Tue Feb 08, 2011 3:11 pm
Posts: 2
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


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.