Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.0 w/ annotations 3.0 beta1
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: Hypersonic SQL
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
I'm trying to implement a relation table with a composite primary key. This table is supposed to associate to entity tables, TableA and TableB :
Code:
@Entity
public class TableA
{
private Long aId;
private Set<RelationTable> relationList = new HashSet<RelationTable>();
....
@OneToMany
@JoinColumn(name = "a_id")
public Set<RelationTable> getRelationList()
{
return relationList;
}
....
}
@Entity
public class TableB
{
private Long bId;
....
}
This is the relation table for "connecting" Table A and TableB. It has a composite primary key.:
Code:
@Entity
public class RelationTable
{
private RelationTablePk relationTableId;
public RelationTable()
{
}
@Id(generate = GeneratorType.NONE)
public RelationTablePk getRelationTableId()
{
return relationTableId;
}
public void setRelationTableId(final RelationTablePk id)
{
this.relationTableId= id;
}
}
This is the primary key class for the above relation table:
Code:
@Embeddable
public class RelationTablePk implements Serializable
{
private TableA tableA;
private TableB tableB;
public RelationTablePk ()
{
}
@JoinColumn(name = "a_id")
public TableA getTableA()
{
return tableA;
}
public void setTableA(final TableA a)
{
this.tableA= a;
}
@JoinColumn(name = "b_id")
public TableB getTableB()
{
return tableB;
}
public void setTableB(final TableB b)
{
this.tableB = b;
}
The above relationship mapping between the RelationTable and the RelationTablePk is working fine. The problem I have is in TableA where I want to get a list of all the RelationTables it is associated with. When I try to get the size of the list in my test class, I get the following exception:
Code:
org.hibernate.exception.GenericJDBCException: could not initialize a collection:
At this point, I want to make sure what I'm trying to do is using the right annotations. Any input would be appreciated.