I have an exception when loading an object with @OneToMany map relation, which seems like a bug. Here is the object class:
Code:
@Entity
@Table(name = "customer")
public class Customer implements java.io.Serializable {
private Integer custId;
private String firstName;
private String middleName;
private String familyName;
private Contact contact;
private BigDecimal discount;
@OneToMany(cascade= CascadeType.ALL, fetch= FetchType.EAGER)
@MapKey(name="addresstype")
private Map<Addresstype, Address> customerAddresses = new EnumMap<Addresstype, Address>(Addresstype.class);
}
The mapping class:
Code:
@Entity
@Table(name = "address", schema="bookstore")
public class Address implements java.io.Serializable {
private Integer addressId;
@Enumerated(EnumType.STRING)
private Addresstype addresstype;
The persistence.xml also contains the default_schema property:
Code:
<property name="hibernate.default_schema" value="bookstore"/>
For loading a Customer object hibernate generates the following sql:
Code:
select
customer0_.custID as custID251_4_,
customer0_.contactID as contactID251_4_,
customer0_.discount as discount251_4_,
customer0_.familyName as familyName251_4_,
customer0_.firstName as firstName251_4_,
customer0_.middleName as middleName251_4_,
addresses1_.customer_custID as customer1_251_6_,
address2_.addressID as addresses2_6_,
(select
a13.addresstype
from
address a13
where
a13.addressID=addresses1_.addresses_addressID) as formula2_6_,
address2_.addressID as addressID283_0_,
address2_.addresstype as addresst2_283_0_,
address2_.city as city283_0_,
address2_.country_ID as country8_283_0_,
address2_.department as department283_0_,
address2_.institution as institut5_283_0_,
address2_.state as state283_0_,
address2_.street as street283_0_,
country3_.ID as ID258_1_,
country3_.abbr as abbr258_1_,
country3_.Name as Name258_1_,
country3_.regionID as regionID258_1_,
region4_.ID as ID272_2_,
region4_.Name as Name272_2_,
contact5_.ID as ID250_3_,
contact5_.email as email250_3_,
contact5_.fax as fax250_3_,
contact5_.tel as tel250_3_,
contact5_.web as web250_3_
from
bookstore.customer customer0_
left outer join
bookstore.customer_address addresses1_
on customer0_.custID=addresses1_.customer_custID
left outer join
bookstore.address address2_
on addresses1_.addresses_addressID=address2_.addressID
left outer join
bookstore.country country3_
on address2_.country_ID=country3_.ID
left outer join
bookstore.region region4_
on country3_.regionID=region4_.ID
left outer join
bookstore.contact contact5_
on customer0_.contactID=contact5_.ID
where
customer0_.custID=?
All tables except the the one in subquery have a schema prefixed and the unprefixed schema causes SQL Error: 0, SQLState: 42P01: "SEVERE: ERROR: relation "address" does not exist". Does somebody know how to solve this problem?