I'm using JPA with
Hibernate 3.2.1 sp1 to establish a ManyToMany relationship between two entities (in the package
com.elite.ehms.model) using a Join Table I hand-crafted:
Code:
@Entity
@Table(name="outreach_queues")
public class Queue implements Serializable
{
@ManyToMany(fetch=FetchType.LAZY, cascade={CascadeType.ALL})
@JoinTable(
name="outreach_queues_employer",
joinColumns=@JoinColumn(name="queueId", referencedColumnName="queueId"),
inverseJoinColumns=@JoinColumn(name="employerId", referencedColumnName="employerId")
)
public Set<Employer> getEmployers() {...}
...
}
@Entity
@Table(name="employer")
public class Employer implements Serializable
{
@ManyToMany(mappedBy="employers", fetch=FetchType.LAZY)
public List<Queue> getQueues() {...}
...
}
CREATE TABLE `outreach_queues_employer` (
`queueemployerId` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`queueId` BIGINT UNSIGNED NOT NULL,
`employerId` BIGINT UNSIGNED NOT NULL,
PRIMARY KEY (`queueemployerId`),
CONSTRAINT `FK_employerId` FOREIGN KEY `FK_employerId` (`employerId`)
REFERENCES `employer` (`employerId`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `FK_queueId` FOREIGN KEY `FK_queueId` (`queueId`)
REFERENCES `outreach_queues` (`queueId`)
ON DELETE CASCADE
ON UPDATE CASCADE
);
The deploy exception I get is: org.hibernate.MappingException: property-ref [
_com_elite_ehms_model_Queue_employers] not found on entity [com.elite.ehms.model.Queue]
Why is the property-ref prefixing the FQCN of the parent entity to the name of the mappedBy property? It also prefixes an underscore and converts the dots to underscores.