Robert de W
Robert de W

Reputation: 306

JPA using @JOINTABLE with additional @JOINCOLUMNs

I'm using JPA to extract data from an existing ERP system. I'm using an (existing) jointable for certain data. The problem is I should also match a column that is not on the join table, but on the source tables itself.

T1 (source)
- F1*
- F2
- F3
- ..

T2 (join)
- F4
- F5

T3 (source)
- F6*
- F7
- F8
- ..

My current join table condition is like this:

@ManyToOne(fetch=FetchType.EAGER, cascade=CascadeType.ALL)
@JoinTable(name="T2", schema=Util.schema, joinColumns = {   
        @JoinColumn(name="F4", referencedColumnName="F2", unique=false),
        @JoinColumn(name="F5", referencedColumnName="F3", unique=false)
    },
    inverseJoinColumns = {
        @JoinColumn(name="F4", referencedColumnName="F7", unique=false),
        @JoinColumn(name="F5", referencedColumnName="F8", unique=false)
    }
}

This works, but how/where do I add the condition T1.F1 = T3.F6?

Upvotes: 2

Views: 2262

Answers (1)

James
James

Reputation: 18379

JPA does not directly allow this. If you are using EclipseLink you could use a DescriptorCustomizer to add additional criteria to your mapping join.

See, http://wiki.eclipse.org/EclipseLink/Examples/JPA/MappingSelectionCriteria

Another option would be to just filter the objects in Java using a get method that filters the collection.

Upvotes: 6

Related Questions