JoinColumn name not used in sql
I have a problem with mapping many-to-one relationship without exact foreign key constraint set in database. I use OpenJPA implementation with MySql database, but the problem is with generated sql scripts for insert and select statements.

I have LegalEntity table which contains RootId column (among others). I also have Address table which has <strong>LegalEntityId</strong> column which is not nullable, and which should contain values referencing LegalEntity's "RootId" column, but without any database constraint (foreign key) set.

Address entity is mapped:
<pre><code>
@Entity
@Table(name="address")
public class Address implements Serializable {
	...

	@ManyToOne(fetch=FetchType.LAZY, optional=false)
	@JoinColumn(referencedColumnName="RootId", name="LegalEntityId", nullable=false, insertable=true, updatable=true, table="LegalEntity")
	public LegalEntity getLegalEntity() {
		return this.legalEntity;
	}
}
</code></pre>
SELECT statement (when fetching LegalEntity's addresses) and INSERT statment are generated:
<pre><code>SELECT t0.Id, .., t0.LEGALENTITY_ID FROM address t0 WHERE t0.LEGALENTITY_ID = ? ORDER BY t0.Id DESC [params=(int) 2]

INSERT INTO address (..., LEGALENTITY_ID) VALUES (..., ?) [params=..., (int) 2]</code></pre>
If I omit table attribute from mentioned statements are generated:
<pre><code>SELECT t0.Id, ... FROM address t0 INNER JOIN legalentity t1 ON t0.LegalEntityId = t1.RootId WHERE t1.Id = ? ORDER BY t0.Id DESC [params=(int) 2]

INSERT INTO address (...) VALUES (...) [params=...]
</code></pre>
So, LegalEntityId is not included in any of the statements.

Is it possible to have relationship based on such referencing (to column other than primary key, without foreign key in database)? Is there something else missing?

Thanks in advance.
JoinColumn name not used in sql
===

I have a problem with mapping many-to-one relationship without exact foreign key constraint set in database. I use OpenJPA implementation with MySql database, but the problem is with generated sql scripts for insert and select statements.

I have LegalEntity table which contains RootId column (among others). I also have Address table which has <strong>LegalEntityId</strong> column which is not nullable, and which should contain values referencing LegalEntity's "RootId" column, but without any database constraint (foreign key) set.

Address entity is mapped:
<pre><code>
@Entity
@Table(name="address")
public class Address implements Serializable {
	...

	@ManyToOne(fetch=FetchType.LAZY, optional=false)
	@JoinColumn(referencedColumnName="RootId", name="LegalEntityId", nullable=false, insertable=true, updatable=true, table="LegalEntity")
	public LegalEntity getLegalEntity() {
		return this.legalEntity;
	}
}
</code></pre>
SELECT statement (when fetching LegalEntity's addresses) and INSERT statment are generated:
<pre><code>SELECT t0.Id, .., t0.LEGALENTITY_ID FROM address t0 WHERE t0.LEGALENTITY_ID = ? ORDER BY t0.Id DESC [params=(int) 2]

INSERT INTO address (..., LEGALENTITY_ID) VALUES (..., ?) [params=..., (int) 2]</code></pre>
If I omit table attribute from mentioned statements are generated:
<pre><code>SELECT t0.Id, ... FROM address t0 INNER JOIN legalentity t1 ON t0.LegalEntityId = t1.RootId WHERE t1.Id = ? ORDER BY t0.Id DESC [params=(int) 2]

INSERT INTO address (...) VALUES (...) [params=...]
</code></pre>
So, LegalEntityId is not included in any of the statements.

Is it possible to have relationship based on such referencing (to column other than primary key, without foreign key in database)? Is there something else missing?

Thanks in advance.