| I am using just JPA mappings and I recently changed to explicit schema names in my mappings. I have a mapping like this (note the specific schema CGY):
@Entity
@Table(schema = "CGY", name = "GUESTS")
public class Guest {
@MapKey(name = "key")
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
@JoinTable(schema = "CGY", name = "GUEST_SETTINGS",
uniqueConstraints = @UniqueConstraint(columnNames = "SETTING_ID"),
joinColumns = @JoinColumn(name = "GUEST_ID", referencedColumnName = "ID"),
inverseJoinColumns = @JoinColumn(name = "SETTING_ID", referencedColumnName = "ID"))
private Map<String, Setting> settings;
The referred-to Setting entity has a mapping also in the CGY schema, like this:
@Entity
@Table(schema = "CGY", name = "SETTINGS")
public class Setting ...
Once I added the explicit schema names to these mappings, the join on the settings property results in an invalid SQL SELECT statement, like this:
select settings0_.guest_id as guest_id1_10_0_, settings0_.setting_id as setting_2_10_0_, (select a0.skey from settings a0 where a0.id=settings0_.setting_id) as formula0_0_, setting1_.id as id1_20_1_, setting1_.created_at as created_2_20_1_, setting1_.modified_at as modified3_20_1_, setting1_.skey as skey4_20_1_, setting1_.val as val5_20_1_ from cgy.guest_settings settings0_ inner join cgy.settings setting1_ on settings0_.setting_id=setting1_.id where settings0_.guest_id=?
and an exception message
Looking back at that SQL, I see the problem in the subquery:
(select a0.skey from settings a0 where a0.id=settings0_.setting_id)
I believe that would work if it added the cgy. table schema prefix, like this:
(select a0.skey from cgy.settings a0 where a0.id=settings0_.setting_id)
|