나는 최근에 웹 애플리케이션의 일반적인 업그레이드에서 Spring 2.5를 3.2로, Hibernate 3를 4.2.8으로 업그레이드했다. 대부분의 작업이 현재 작동하지만, 작동하지 않고 나를 혼란에 빠뜨린 하나의 Criteria 트랜잭션이 있습니다. 새 버전은 결과를 반환하지 않지만 오류는 반환하지 않으며 이전 버전은 요청 된 값을 올바르게 검색합니다.3에서 4 로의 Hibernate 업그레이드 : 조건 트랜잭션이 작동을 멈춘다.
코드는 이전 버전과 새 버전에서 동일한 코드이며 도달하는 인수가 동일하다는 것을 확인했습니다.
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(
name = "type",
discriminatorType = DiscriminatorType.STRING
)
@Table(name = "informationresource")
abstract public class AbstractInformationResource extends PersistentEntity<String> {
private static final long serialVersionUID = 8709376067232042462L;
@Id @GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid", strategy = "uuid")
private String id;
@Column(nullable = false)
private String name;
@Column(nullable = false)
private int sort;
public String getId() {
return id;
}
public String getName() {
return name;
}
public int getSort() {
return sort;
}
}
그리고 원래 PersistentEntity : 그것은 확장하는 추상 클래스에 관해서는
@Entity
@DiscriminatorValue("viewing")
public class ViewingResource extends AbstractInformationResource {
private static final long serialVersionUID = -4569093742552159052L;
@OneToOne(targetEntity = Attribute.class, fetch = FetchType.LAZY)
@JoinColumn
private Attribute primaryAttribute;
@OneToMany(targetEntity = Viewing.class, cascade = {CascadeType.PERSIST, CascadeType.MERGE}, orphanRemoval=true)
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
@JoinTable(name = "informationresource_viewings")
@OrderBy("sort")
private Set<ResourceViewing> viewings;
public Set<ResourceViewing> getViewings() {
return viewings;
}
public Attribute getPrimaryAttribute() {
return primaryAttribute;
}
}
:
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(ViewingResource.class);
criteria.createCriteria("viewings","currentViewings");
criteria.add(Property.forName("currentViewings.id").eq(viewingId));
ViewingResource result = (ViewingResource)criteria.uniqueResult();
ViewingResource는 다음과 같이 정의되어 내 법인이며, 다음은 자바 코드는 id와 주석이없는 Serializable의 확장 일뿐입니다.
나는 최대 절전 모드 로그를 활성화하고, Hibernate는 SQL 문자열이 방법에서 차이가 발생에 대한 문제가, 주석 최대 절전 모드 3과 4 사이의 작업 방식에있을 수 있습니다 발견최대 절전 모드 3 :
select
... (maps to all columns)
from
informationresource this_
inner join
informationresource_viewings viewings3_
on this_.id=viewings3_.informationresource_id
inner join
Viewing currentvie1_
on viewings3_.viewings_id=currentvie1_.id
where
this_.type in (
'viewing', 'directory'
)
and currentvie1_.id=?
최대 절전 모드 4에서 생성 된 SQL이 수행하는 반면 어떤 조인 :
select
... (maps to all columns, except type, attributeType and fieldName)
from
informationresource this_,
informationresource_viewings viewings3_,
Viewing currentvie1_
where
this_.id=viewings3_.informationresource_id
and viewings3_.viewings_id=currentvie1_.id
and this_.type='viewing'
and currentvie1_.id=?
나에게이 문제를 사전에 도움이 될 수 있습니다 어떤 힌트를? 현재 내 생각으로는 Hibernate 3 이후로 변경되거나 수정 된 일부 주석 정의를 건너 뛸 수도 있지만, 지금까지 선언 한 방식으로 불법적 인 것을 찾을 수 없었고 @Join을 수정하려는 시도가있었습니다. 지금까지 성공하지 못했습니다.
EDIT. 이 문제를 잠시 접하면서, 나는이 문제가 추상 클래스의 @DiscriminatorColumn과 관련이 있다는 것을 발견했다. 나는이 유형의 요청에 대한 내 유형이 결코 '보기'가 아니라 '디렉토리'라는 문제가 있음을 발견했습니다. 이전 생성 된 SQL에서 나는 두 가지 유형이 생성했다 : 그것은 내가 새로운 SQL이 줄을 변경
and this_.type='viewing'
및 :
this_.type in (
'viewing', 'directory'
)
그러나 새로운 SQL이는 '보기'로 제한됩니다
필요한 올바른 값을 반환합니다. 열 유형에는 'viewing'과 'directory'의 두 값만 있습니다. 그래서 지금 제 질문은 '보기'유형을 강요하는 대신에 유형을 묻는 기준을 만드는 방법입니다.