Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate @WhereJoinTable trouble

I'm getting used to hibernate but every now and again I hit a stumble, here's another one.

I'm trying to achieve the following:

@OneToMany
@JoinTable(name = "inter_spec",
        joinColumns = { @JoinColumn(name = "inter_id") },
        inverseJoinColumns = { @JoinColumn(name = "spec_id") })
@WhereJoinTable(clause = "spec_type=SECTION")
public List<Section> getSections() {
    return sections;
}

But I get the following error when running my unit test:

[ERROR] JDBCExceptionReporter - Column "SECTIONS0_.SECTION" not found; SQL statement:

All I want is to apply the Where clause so my List sections has only the SECTION type data.

If I remove the Where clause my unit test passes, the assertion on the List has the expected data.

Thanks for reading.

like image 917
C0deAttack Avatar asked Feb 14 '11 14:02

C0deAttack


1 Answers

Ahh, this always happens, as soon as I post a question I figure it out!!

Basically, SECTION in the Where clause is an Enum in the Java code, so that line should have been:

@WhereJoinTable(clause = "spec_type='SECTION'")

Notice the single quotes around SECTION which weren't there before!

like image 180
C0deAttack Avatar answered Oct 12 '22 11:10

C0deAttack