-1

I have an existing DB that two tables are joined based on a string. The problem is that one table column is defined as a varchar2 and the other is a char. Oracle will pad the char with spaces and the varchar2 will not so that when JPA tries to join the two one has space and one does not so the equality is not met.

How can I get the join to work in JPA? Is there a JPA annotation that would do the trick?

KRico
  • 501
  • 2
  • 6
  • 13
  • "JPA" is an interface; it doesn't do anything so can't work or otherwise. Maybe it doesn't work with your *implementation* (you don't say which one), but maybe it works with a different implementation. Without your definition of the "problem" its all pointless – Neil Stockton Dec 09 '14 at 15:57

1 Answers1

0

What I finally did was to use @Subselect.

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@javax.persistence.Entity
@Table( schema="SECURITYDBO", name = "XREFERENCE")
@Subselect("SELECT " +
" ,cast( trim(aCharColumn) as varchar(100) ) AS aCharColumn" + // NEED TO TRIM SO THAT JPA INNER JOINED BETWEEN 2 tables WHICH IS A VARCHAR AND THIS ONE THERE WILL NOT BE ANY SPACES PADDED
"FROM MYTABLE ")
public class MyJPA extends XReference{
....

KRico
  • 501
  • 2
  • 6
  • 13