Я пытаюсь получить данные от ассоциации N: N, но я получаю пустое поле.
Есть мой класс отображения Hibernate:
@Entity
@Table(name = "companies")
public class Company extends NamedEntity {
//some_code
@ManyToMany(
targetEntity = com.hqcargo.shippingstock.domain.CompanyProfile.class,
cascade = {CascadeType.ALL, CascadeType.ALL },
fetch = FetchType.EAGER
)
@JoinTable(
name = "company_company_profiles",
joinColumns = {@JoinColumn(
name = "company_id",
referencedColumnName = "id") },
inverseJoinColumns = {@JoinColumn(
name = "company_profile_id",
referencedColumnName = "id") }
)
private List<CompanyProfile> profiles;
// getters and setters + other code
другой класс:
@Entity
@Table(name = "company_profiles")
public class CompanyProfile extends NamedEntity {
//some_code
@ManyToMany(
targetEntity = com.hqcargo.shippingstock.domain.Company.class,
cascade = {CascadeType.ALL, CascadeType.ALL },
mappedBy = "profiles",
fetch = FetchType.EAGER
)
@JoinTable(
name = "company_company_profiles",
joinColumns = {@JoinColumn(
name = "company_profile_id",
referencedColumnName = "id") },
inverseJoinColumns = {@JoinColumn(
name = "company_id",
referencedColumnName = "id") }
)
private List<Company> companies;
// getters and setters + other code
Этот класс отлично работает с сохранением, но не с загрузкой данных.
Ниже я добавляю класс DAO:
public class CompanyJpaDAO extends JpaDaoSupport
implements CompanyDAO {
@Transactional(readOnly = true)
public Company readById(Long id) {
Company tempCompany = getJpaTemplate().find(Company.class, id);
return tempCompany;
}
}
@Transactional
public void update(Company existingInstance) {
if (existingInstance.isNew()) {
throw new InvalidDataAccessApiUsageException(
"Can't update record. Given instance don't have assigned ID");
}
save(existingInstance);
}
, когда я обновляю все в порядке (сгенерированный sql Hibernate):
251252 [13627369@qtp-8132032-9] DEBUG org.hibernate.SQL -
update
companies
set
name=?,
where
id=?
Hibernate:
update
companies
set
name=?,
where
id=?
251295 [13627369@qtp-8132032-9] DEBUG org.hibernate.SQL -
insert
into
company_company_profiles
(company_id, company_profile_id)
values
(?, ?)
Hibernate:
insert
into
company_company_profiles
(company_id, company_profile_id)
values
(?, ?)
но когда я загружаю данные, я не получаю информацию из company_company_profiles (sql, сгенерированной Hibernate)
36088 [13507994@qtp-8132032-13] DEBUG org.hibernate.SQL -
select
companies0_.company_profile_id as company2_8_,
companies0_.company_id as company1_8_,
company1_.id as id3_0_,
company1_.name as name3_0_,
from
company_company_profiles companies0_
left outer join
companies company1_
on companies0_.company_id=company1_.id
where
companies0_.company_profile_id=?
Hibernate:
select
companies0_.company_profile_id as company2_8_,
companies0_.company_id as company1_8_,
company1_.id as id3_0_,
company1_.name as name3_0_,
from
company_company_profiles companies0_
left outer join
companies company1_
on companies0_.company_id=company1_.id
where
companies0_.company_profile_id=?
Вы видите какие-либо ошибки в моем коде?