2012-05-27 3 views
2

JPA를 처음 사용합니다. Java 및 JPA로 코드를 작성합니다. 내 코드는 아래와 같습니다.org.hibernate.QueryException : 특성을 확인할 수 없습니다.

String queryStr = "SELECT m.title, b.isbn, b.authors"; 
    queryStr += " FROM Book b, Media m"; 
    queryStr += " WHERE m.MediaID = b.MediaID"; 
      queryStr += " AND b.isbn = '" + isbn + "' AND m.title = '%" + title +"%'"; 
Query query = em.createQuery(queryStr); 

제 코드에서 클래스 북은 클래스 미디어를 확장합니다.

하지만

org.hibernate.QueryException 인 오류가 발생했습니다 : 부동산을 확인할 수 없습니다 :의 MediaID : mediaManagement.Media [SELECT m.title, b.isbn, mediaManagement FROM b.authors합니다. 도서 b, 미디어 관리. 미디어 m 어디 m.MediaID = b. 미디어 ID]

이것은 미디어 클래스입니다.

@Entity 
@Inheritance(strategy = InheritanceType.JOINED) 
@Table(name = "Media") 
@NamedQuery(name = "findAllMedias", query = "select b from Media b") 
public class Media { 

@Id 
@Column(name = "MediaID") 
@GeneratedValue(strategy = GenerationType.IDENTITY) 
private int mediaID; 

/** 
* Getter of the property <tt>mediaID</tt> 
* 
* @return Returns the mediaID. 
* @uml.property name="mediaID" 
*/ 
public int getMediaID() { 
    return mediaID; 
} 

/** 
* Setter of the property <tt>mediaID</tt> 
* 
* @param mediaID 
*   The mediaID to set. 
* @uml.property name="mediaID" 
*/ 
public void setMediaID(int mediaID) { 
    this.mediaID = mediaID; 
} 

/** 
* @uml.property name="title" 
*/ 
@Column(name = "title") 
private String title; 

/** 
* Getter of the property <tt>title</tt> 
* 
* @return Returns the title. 
* @uml.property name="title" 
*/ 
public String getTitle() { 
    return title; 
} 

/** 
* Setter of the property <tt>title</tt> 
* 
* @param title 
*   The title to set. 
* @uml.property name="title" 
*/ 
public void setTitle(String title) { 
    this.title = title; 
} 

/** 
* @uml.property name="editionDate" 
*/ 

private Calendar editionDate; 

/** 
* Getter of the property <tt>editionDate</tt> 
* 
* @return Returns the editionDate. 
* @uml.property name="editionDate" 
*/ 
public Calendar getEditionDate() { 
    return editionDate; 
} 

/** 
* Setter of the property <tt>editionDate</tt> 
* 
* @param editionDate 
*   The editionDate to set. 
* @uml.property name="editionDate" 
*/ 
public void setEditionDate(Calendar editionDate) { 
    this.editionDate = editionDate; 
} 

/* 
* Two medias are equal if their mediaID is the same 
*/ 
@Override 
public boolean equals(Object media) { 
    if (media == null) 
     return false; 
    Media b = (Media) media; 

    if (b.mediaID == mediaID) 
     return true; 

    return false; 
} 

public Media() { 
}; 

/** 
* Creates a media All parameters should be given 
* 
* @param title 
*   the title of the media 
* 
* @param editionDate 
*   date of the edition of the media 
* 
* @throws BadParametersException 
*/ 
public Media(String title, Calendar editionDate) 
     throws BadParametersException { 
    if ((title == null) || (editionDate == null)) 
     throw new BadParametersException(); 

    this.title = title; 
    this.editionDate = editionDate; 

} 

/** 
* Returns a description of the media 
*/ 
public String toString() { 
    return this.title + " " + String.valueOf(this.title); 
} 

/** 
* @uml.property name="copies" 
* @uml.associationEnd multiplicity="(0 -1)" inverse="media:copyManagement.Copy" 
*/ 
@OneToMany(mappedBy="mediaRef") protected Set<Copy> copies; 

public void addCopy(Copy copy) { 
    copies.add(copy); 
} 

/** 
* Getter of the property <tt>copies</tt> 
* @return Returns the copies. 
* @uml.property name="copies" 
*/ 
public Set<Copy> getCopies() { 
    return copies; 
} 

/** 
* Setter of the property <tt>copies</tt> 
* @param editionDate The copies to set. 
* @uml.property name="copies" 
*/ 
public void setCopies(Set<Copy> copies) { 
    this.copies = copies; 
} 

그리고 이것은 책 클래스입니다.

@Entity 
@Table(name = "Book") 
@NamedQuery(name = "findAllBooks", query = "select b from Book b") 
public class Book extends Media { 
/** 
* @uml.property name="authors" 
*/ 
@Column(name = "authors") 
private ArrayList<String> authors; 

/** 
* Getter of the property <tt>authors</tt> 
* 
* @return Returns the authors. 
* @uml.property name="authors" 
*/ 
public ArrayList<String> getAuthors() { 
    return authors; 
} 

/** 
* Setter of the property <tt>authors</tt> 
* 
* @param authors 
*   The authors to set. 
* @uml.property name="authors" 
*/ 
public void setAuthors(ArrayList<String> authors) { 
    this.authors = authors; 
} 

/** 
* @uml.property name="isbn" 
*/ 

@Column(name = "isbn") 
private String isbn; 

/** 
* Getter of the property <tt>isbn</tt> 
* 
* @return Returns the isbn. 
* @uml.property name="isbn" 
*/ 
public String getisbn() { 
    return isbn; 
} 

/** 
* Setter of the property <tt>isbn</tt> 
* 
* @param isbn 
*   The isbn to set. 
* @uml.property name="isbn" 
*/ 
public void setisbn(String isbn) { 
    this.isbn = isbn; 
} 

public Book() { 
    // TODO Auto-generated constructor stub 
} 

public Book(String title, Calendar editionDate, ArrayList<String> authors, 
     String isbn) throws BadParametersException { 
    super(title, editionDate); 
    this.authors = authors; 
    this.isbn = isbn; 
    // TODO Auto-generated constructor stub 
} 

} 

누구든지 도움을받을 수 있습니까?

+1

매핑 파일 (사용 된 경우)을 사용하여 질문에'Media' 및'Book' 클래스를 게시 할 수 있습니까? – darrengorman

+0

이미 게시했습니다 – user1412944

답변

3

미디어가 확장되면 미디어 테이블에 가입하는 이유는 무엇입니까? (Book과 Media 클래스와 매핑을 사용하면 더 쉬울지라도)

"Book"객체를 쿼리하면 충분합니다. 또한 "MediaId"는 "mediaId"여야합니다. Hibernate는 그것의 프라퍼티 이름에서 대소 문자를 구분한다.

+0

실제로 내가 추가 한 것을 잊은 후 어디에서 m.MediaID = b.MediaID 후 – user1412944

관련 문제