Hi, I don't seem to get near a solution, so can someone tell me why this isn't working?
I have a Channel class that looks like this:
Code:
...
@Id
@GeneratedValue(generator = "channel-id")
@GenericGenerator(name = "channel-id", strategy = "increment")
public Long getId() {
return id;
}
...
@ManyToOne
@JoinColumn(name = "parent")
public Channel getParent() {
return parent;
}
...
@OneToMany(mappedBy = "parent")
public Set<Channel> getSubchannels() {
return subchannels;
}
...
And a corresponding JUnit test which is:
Code:
@Before
public void setUp() throws Exception {
Channel c = new Channel();
c.setName(CHNAME);
this.channelDao.create(c);
Channel subc = new Channel();
subc.setName(SUBCHNAME);
subc.setParent(c);
this.channelDao.create(subc);
c = new Channel();
c.setName(SUBCHNAME + 2);
c.setParent(subc);
this.channelDao.create(c);
c = new Channel();
c.setName(CHNAME + 2);
this.channelDao.create(c);
}
public void testGetById() {
Channel c = this.channelDao.getById(1L);
assertNotNull(c);
assertEquals(CHNAME, c.getName());
assertNull(c.getParent());
c.getSubchannels();
--> assertEquals(1, c.getSubchannels().size());
c = this.channelDao.getById(3L);
assertNotNull(c);
assertEquals(SUBCHNAME + 2, c.getName());
assertNotNull(c.getParent());
assertEquals(2, (long)c.getParent().getId());
}
Unfortunately the subchannels list does not contain any elements. All other asserts pass. Application start up does not give me any errors, the only valuable information I get is:
Code:
Second pass for collection: com.wochs.api.timeframe.model.Channel.subchannels
DEBUG CollectionBinder - Binding a OneToMany: com.wochs.api.timeframe.model.Channel.subchannels through a foreign key
INFO CollectionBinder - Mapping collection: com.wochs.api.timeframe.model.Channel.subchannels -> channel
DEBUG TableBinder - Retrieving property com.wochs.api.timeframe.model.Channel.parent
DEBUG CollectionSecondPass - Mapped collection key: parent, one-to-many: com.wochs.api.timeframe.model.Channel
which looks totally right for me.
The test database is hsqldb and is created with hibernate.hbm2ddl.auto tool.
Can someone please tell me where I go wrong?[/code]