JPAContainer - many-to-one or one-to-one mapping

This question may be more of a Hibernate or Eclipse issue, but I hope someone can help me… I suspect the answer to this question may help solve the question I asked about the JPAContainer and the foreign key filtering yesterday…

I have a database with 2 tables that are related as follows (I’ve edited out lots of extraneous stuff). Using Eclipse, I have created java classes for the tables (new entities from tables).

public class RrdRecord implements Serializable {
	private static final long serialVersionUID = 1L;

	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Basic(optional = false)
	@Column(name = "id")
	private Integer id;

	private String rrdPath;

	//bi-directional many-to-one association to TrafficReportPort
	private Set<TrafficReportPort> trafficReportPorts;

etc. etc.

The fact is, that there is actually at MOST a single TrafficReportPort record for a given RRDRecord object (and there may be no record at all). So I would like to change the OneToMany mapping to a OneToOne mapping and use a single TrafficReportPort object instead of a Set. But Eclipse just tells me that OneToOne is an illegal statement in that location.

I added a routine called getTrafficReportPort which looks at the set and returns the one element if it is there. By doing that, I was able to add a nested property to one of my tables and it displays the trafficReportPort description field successfully. But where it fails is trying to construct a filter and I think that is because the property is a set instead of a single object.

So my question is - how do I describe the system so I have a one-to-one mapping instead of one-to-many? If I can fix that, perhaps my filter problem will go away, but I won’t know until I get past this one…

Thanks in advance,


After much digging, I found the correct way to create a one-to-one mapping, and that seems to have solved this issue, as well as the JPAContainer filter problem that I asked about the other day.

For the record, the code looks like this:

In the RRDRecord class:

private TrafficReport trafficReport;

and in the TrafficReport object:

private RrdRecord rrdRecord;

This, along with the appropriate getters and setters seems to work.