Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.0.4 and Annotations 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:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
I have the following two classes:
Code:
@Entity
public class ClassA
{
private Long id;
private ClassB firstParty;
private ClassB secondParty;
@Id(generate = GeneratorType.AUTO)
public Long getId()
{
return id;
}
@ManyToOne
@JoinColumn(name = "first_party_id", referencedColumnName = ClassB.PK_COLUMN_NAME, nullable = false)
public ClassB getFirstParty()
{
return firstParty;
}
@ManyToOne
@JoinColumn(name = "second_party_id", referencedColumnName = ClassB.PK_COLUMN_NAME, nullable = false)
public ClassB getSecondParty()
{
return secondParty;
}
// Corresponding setters are here
// ......
}
Here's the second class that the first class has a relationship to:
Code:
@Entity
public class ClassB
{
public static final String PK_COLUMN_NAME = "id";
private Long id;
private Set<ClassA> firstRelationships = new HashSet<ClassA>();
private Set<ClassA> secondRelationships = new HashSet<ClassA>();
@Id(generate = GeneratorType.AUTO)
@Column(name = PK_COLUMN_NAME)
public Long getId()
{
return id;
}
@OneToMany(mappedBy = "firstParty")
public Set<ClassA> getFirstRelationships()
{
return firstRelationships;
}
@OneToMany(mappedBy = "secondParty")
public Set<ClassB> getSecondRelationships()
{
return secondRelationships;
}
// Insert corresponding setters here
// .......
}
My question is that is this mapping the right way to go? I don't have any errors for this but whenever I run test cases for these kind of classes, it takes a lot longer to execute. I wanted to make sure the design itself wasn't flawed.