1

このエラーの別のケースを次に示します。

21:22:15,881 ERROR [SessionFactoryImpl] Error in named query: ch.software.gvs.TroubleNotification_DeviceType.byType org.hibernate.QueryException: 
could not resolve property: type of: ch.ildsoftware.gvs.TroubleNotification_DeviceType
[select d.id from ch.ildsoftware.gvs.TroubleNotification_DeviceType d where d.type = :type]

次の設定があります:

query.xml:

<named-query name="ch.ildsoftware.gvs.TroubleNotification_DeviceType.byType">
    <query>
    select t.id from TroubleNotification_DeviceType t where t.type = :type
    </query>        
</named-query>

TroubleNotification_DeviceType.java

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "tblgwTroubleNotification_ADSTyp")
public class TroubleNotification_DeviceType implements Serializable {

private static final long serialVersionUID = 1L;

private TroubleNotification id;
private DeviceType type;
private String createdBy;
private String createdDate;

public TroubleNotification_DeviceType() 
{}

public TroubleNotification_DeviceType(TroubleNotification id, DeviceType type) {
    this.id = id;
    this.type = type;
}

@Id
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "IDgwTroubleNotification", nullable = false)
public TroubleNotification getId() {
    return id;
}

public void setId(TroubleNotification id) {
    this.id = id;
}

@Id
@Column(name = "ADSTypID", nullable = false)
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "GeraeteTypID", nullable = false)
public DeviceType getType() {
    return type;
}

public void setType(DeviceType type) {
    this.type = type;
}

@Column(name = "Created", nullable = false)
public String getCreatedBy() {
    return createdBy;
}

public void setCreatedBy(String createdBy) {
    this.createdBy = createdBy;
}

@Column(name = "CreatedDate", nullable = false)
public String getCreatedDate() {
    return createdDate;
}

public void setCreatedDate(String createdDate) {
    this.createdDate = createdDate;
}
}

@Column および @JoinColumn アノテーションに何か問題があるのではないかと思います。私が参加している列名は、列名に別名を付けるビューからのものです。しかし、何か他のことが間違っているかもしれません。私はこれにかなり慣れていません。

DeviceType からのスニペット:

private static final long serialVersionUID = 1L;
private Integer id;
private String name;

    ....

@Id
@Column(name = "GeraeteTypID", nullable = false)
public Integer getId()
{
    return this.id;
}

他のクラスでは、参照は次のようになり、うまく機能します (ただし、列名は同じです)。

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "GeraeteTypID", nullable = false)
public DeviceType getType()
{
    return this.type;
}

EJB からのスニペット:

@Override
@SuppressWarnings("unchecked")
public List<TroubleNotification> getTroubleNotificationByDeviceType(DeviceType aType)
{
    // first get all IDgwTroubleNotification for ADSTypID
    Query idSet = gvsData.createNamedQuery(
            TroubleNotification_DeviceType.class.getName() + ".byType");
    idSet.setParameter("type", aType);
    List<TroubleNotification> idSetResult = idSet.getResultList();

    final List<TroubleNotification> troubleNotificationResult = new ArrayList<TroubleNotification>();
    for (int i = 0; i <  idSetResult.size(); i++) {
        // get all Notification for IDgwTroubleNotification
        Query notificationById = gvsData.createNamedQuery(
                TroubleNotification.class.getName() + ".byId");
        notificationById.setParameter("id", idSetResult.get(i));
        troubleNotificationResult.add((TroubleNotification) notificationById.getResultList());
    }
    return troubleNotificationResult;
}

ご協力ありがとうございました!

4

1 に答える 1

0

DB マッピングがまったく適切ではないことがわかりました。n:m 関係がありますが、休止状態では簡単ではないようです。しかし、これは非常に役に立ちました: Hibernate Many-To-Many Revisited

しかし、それでも問題は解決しませんでした。そして、複合主キーがあり、2 つのテーブルの主キーが n:m テーブルにマップされていることを発見しました。もう1つのそれほど簡単ではない設定。だから私はこのスレッドに従いました:複合主キーと注釈を使用した ManyToMany のマッピング:

2 番目のリンクの構成は、最初のリンクの 2 番目の戦略に従った SQL ステートメントと共に機能します。

于 2013-02-08T16:02:03.920 に答える